forked from philpraxis/lig
-
Notifications
You must be signed in to change notification settings - Fork 6
/
lig.c
775 lines (665 loc) · 24.2 KB
/
lig.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
/*
* lig.c --
*
* lig -- LISP Internet Groper
*
* Copyright (c) 2010, David Meyer <[email protected]>
* All rights reserved.
*
* David Meyer
* Thu Apr 9 09:44:57 2009
*
* IPv6 support added by Lorand Jakab <[email protected]>
* Mon Aug 23 15:26:51 2010 +0200
*
* Machine parsable output added by Job Snijders <[email protected]>
* Wed Dec 15 11:38:42 CET 2010
*
* Instance ID support added by Lorand Jakab <[email protected]>
* Thu Jul 26 00:50:51 PDT 2012
*
* Map-Register and Non-encapsulated Map-Request Functionality added by Alexandru Iuhas <[email protected]>
* Mon May 27 17:00:20 2013, Polytechnic University of Catalonia
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* o Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* o Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* o Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*
* $Header: /mnt/disk1/dmm/src/lig/RCS/lig.c,v 1.1 2010/11/14 20:46:22 dmm Exp $
*
*/
#include "lig.h"
#include "lig-external.h"
#include "send_map_request.h"
#include "lispmob/lispd_iface_list.h"
#include "lispmob/lispd_external.h"
#include "lispmob/lispd_lib.h"
#include "lispmob/lispd_locator.h"
#include "lispmob/lispd_map_register.h"
#include "lispmob/lispd_pkt_lib.h"
#include "lispmob/lispd_sockets.h"
#include "lispmob/lispd_log.h"
#include "lispmob/lispd_mapping.h"
#include "lispmob/lispd_config.h"
/*
* globals
*/
int ctrl_socket; /* socket to send / receive packets*/
unsigned int *nonce;
uchar packet[MAX_IP_PACKET];
/*
* use these to construct and parse packets
*/
struct ip *iph;
struct udphdr *udph;
struct map_reply_pkt *map_reply;
/*
* global options
*/
unsigned int udp_checksum_disabled = 0;
unsigned int debug = 0;
unsigned int machinereadable = 0;
unsigned int disallow_eid = 0;
unsigned int mreg = 0; // used to specify it is a map-register message
int32_t iid = -1;
int encapsulate = 1;
int check = 0;
/*
* Set the locator paramaters priority, weight, mpriority, mweight
* and the Reachability bit to their default values
*/
void set_locator_defaults(
uint8_t *priority,
uint8_t *weight,
uint8_t *mpriority,
uint8_t *mweight,
uint8_t *reach);
int main(int argc, char *argv[])
{
struct addrinfo hints;
struct addrinfo *res;
struct timeval before;
struct timeval after;
struct protoent *proto;
struct sockaddr_storage from;
struct sockaddr_storage my_addr;
/*
* Remember the requested eid and map resolver properties here
*/
char *eid = NULL;
char *src_ip_addr = NULL;
char *src_eid_addr = NULL;
char *eid_name = NULL;
char *mr_name = NULL;
char *progname = NULL;
char *map_resolver = getenv(LISP_MAP_RESOLVER); /* check for env var */
int mr_addrtype = 0;
int mr_length = 0;
int wait_for_reply = TRUE;
struct sockaddr *src_eid_ptr = NULL;
struct sockaddr_storage src_eid;
struct sockaddr_storage eid_addr;
struct sockaddr_storage map_resolver_addr;
/*
* The following are used in the map-register function
*/
int src_addrtype = 0;
lispd_mapping_elt *mapping = NULL;
char *eidpref = NULL;
lisp_addr_t *eid_prefix = 0;
uint8_t eid_prefix_length = 0;
char *loc = NULL;
lispd_locator_elt *locator = NULL;
lisp_addr_t *locator_addr = 0;
uint8_t priority = 1;
uint8_t weight = 100;
uint8_t mpriority = 1;
uint8_t mweight = 100;
char *map_server_addr = getenv(LISP_MAP_RESOLVER);
uint8_t proxy = 1;
uint8_t reach = UP;
char *pass = NULL;
int i = 0; /* generic counter */
unsigned int iseed = 0; /* initial random number generator */
unsigned int nonce0 = 0;
unsigned int nonce1 = 0;
/*
* Get defaults
*/
int count = COUNT;
int timeout = MAP_REPLY_TIMEOUT;
unsigned int port = 0; /* if -p <port> specified, put it in here to find overflow */
emr_inner_src_port = 0;
/*
* Variables used for filling in the map-register message
*/
mnot = 0; // Map-Notify bit
auth = 1; // Authoritative bit
recordttl = htonl(DEFAULT_MAP_REGISTER_TIMEOUT); // Record TTL
mapvers = 0; // Map Version
/*
* Variables used for filling in the map request message
*/
mrauth = 0; // Authoritative bit
probe = 0; // RLOC Probe bit
smr = 0; // SMR bit
smri = 0; // SMR-invoked bit
/*
* Temporary data
*/
int e = 0; /* generic errno holder */
char buf[NI_MAXHOST]; /* buffer for getnameinfo() results */
/*
* parse args //modified for long opts
*/
int opt = 0;
char *optstring = "bwc:dei:m:p:t:s:uvr";
int longindex = 0;
static struct option long_options[] = {
{"noproxy", no_argument, 0, '0'},
{"mnot", no_argument, 0, '1'},
{"recordttl", required_argument, 0, '2'},
{"eidmlen", required_argument, 0, '3'},
{"notauth", no_argument, 0, '4'},
{"mapvers", required_argument, 0, '5'},
{"eidpref", required_argument, 0, '6'},
{"locator", required_argument, 0, '7'},
{"locpr", required_argument, 0, '8'},
{"locw", required_argument, 0, '9'},
{"locmpr", required_argument, 0, 'z'},
{"locmw", required_argument, 0, 'y'},
{"notreach", no_argument, 0, 'x'},
{"pass", required_argument, 0, 'k'},
{"addloc", no_argument, 0, 'a'},
{"mrauth", no_argument, 0, 'h'},
{"probe", no_argument, 0, 'o'},
{"smr", no_argument, 0, 'q'},
{"smri", no_argument, 0, 'n'},
{"noencap", no_argument, 0, 'l'},
{"srceid", required_argument, 0, 'f'},
{"nowait", no_argument, 0, 'w'}
};
while ((opt = getopt_long (argc, argv, optstring, long_options, &longindex)) != -1) {
switch (opt) {
case 'w':
wait_for_reply = FALSE;
break;
case '0':
proxy = 0; // Proxy Reply bit
break;
case '1':
mnot = 1; // want Map Notify
break;
case '2':
recordttl = atoi(optarg);
break;
case '3': //create the new mapping element with the
eid_prefix_length = atoi(optarg); //eid prefix address and length specified
mapping = new_local_mapping(*eid_prefix, eid_prefix_length, iid);
if(mapping == NULL) {
lispd_log_msg(LISP_LOG_ERR, "mapping");
free(eid_prefix);
exit(BAD);
}
break;
case '4':
auth = 0; // Authoritative bit
break;
case '5':
mapvers = atoi(optarg); // Map Version
break;
case '6':
eid_prefix = (lisp_addr_t *)malloc(sizeof(lisp_addr_t));
eidpref = strdup(optarg);
get_lisp_addr_from_char(eidpref, eid_prefix); // get the eid prefix address
break;
case '7':
locator_addr = (lisp_addr_t *)malloc(sizeof(lisp_addr_t));
if ((loc = strdup(optarg)) == NULL) {
perror ("strdup(loc)");
exit(BAD);
}
get_lisp_addr_from_char(loc, locator_addr); // get the locator address
check = 1;
break;
case '8':
priority = atoi(optarg);
break;
case '9':
weight = atoi(optarg);
break;
case 'z':
mpriority = atoi(optarg);
break;
case 'y':
mweight = atoi(optarg);
break;
case 'x':
reach = DOWN;
break;
case 'k': // the Map Server password used to encode with HMAC
pass = strdup(optarg);
break;
case 'a':
if (check == 1){
locator = new_local_locator(locator_addr, reach, priority, weight, mpriority, mweight, 0); //generate the locator element
if(locator == NULL) {
lispd_log_msg(LISP_LOG_ERR, "locator");
free(locator_addr);
exit(BAD);
}
if ( add_locator_to_mapping(mapping, locator) != GOOD ) { //add the locator element to the mapping
lispd_log_msg(LISP_LOG_ERR, "Error adding locator to the mapping");
exit(BAD);
}
set_locator_defaults(&priority, &weight, &mpriority, &mweight, &reach); //reset the locator parameters for the next entry
check = 0;
}
else{
printf("WARNING: The --locator option must be specified before each new --addloc option\n");
}
break;
case 'b':
machinereadable += 1;
break;
case 'c':
count = atoi(optarg);
if ((count < MIN_COUNT) || (count > MAX_COUNT)) {
fprintf(stderr,
"%s: Invalid number, specify count in the range (%u:%u)\n",
argv[0], MIN_COUNT,MAX_COUNT);
exit(BAD);
}
break;
case 'd':
debug += 1;
break;
case 'e':
disallow_eid = 1;
break;
case 'f':
if ((src_eid_addr = strdup(optarg)) == NULL) {
perror ("strdup(src_eid_addr)");
exit(BAD);
}
break;
case 'i':
iid = atoi(optarg);
if ((iid < 0) || (iid > MAX_IID)) {
fprintf(stderr,
"%s: Invalid Instance ID, specify count in the range (%u:%u)\n",
argv[0], 0, MAX_IID);
exit(BAD);
}
printf("Using Instance ID %d\n", iid);
break;
case 'p':
if ((port = atoi(optarg)) > MAX_EPHEMERAL_PORT) {
fprintf(stderr, "%s: Invalid port (%d)\n", argv[0], port);
exit(BAD);
}
emr_inner_src_port = (ushort) port;
break;
case 'm':
if ((map_resolver = strdup(optarg)) == NULL) {
perror ("strdup(map_resolver)");
exit(BAD);
}
if ((map_server_addr = strdup(optarg)) == NULL) {
perror ("strdup(map_server)");
exit(BAD);
}
break;
case 'r': // Specify it is a Map register message
mreg = 1;
/*
* Run through the interfaces and select a usable address as the source address
*/
if(load_interface_list() != 1) {
lispd_log_msg(LISP_LOG_ERR, "load_interface_list");
exit(BAD);
}
set_default_ctrl_ifaces();
break;
case 's':
if ((src_ip_addr = strdup(optarg)) == NULL) {
perror ("strdup(src_ip_addr)");
exit(BAD);
}
break;
case 't':
timeout = atoi(optarg);
if ((timeout < MIN_MR_TIMEOUT) || (timeout > MAX_MR_TIMEOUT)) {
fprintf(stderr,
"%s: Invalid number, specify timeout in the range (%u:%u) seconds\n",
argv[0], MIN_MR_TIMEOUT,MAX_MR_TIMEOUT);
exit(BAD);
}
break;
case 'u':
udp_checksum_disabled = 1;
break;
case 'h':
mrauth = 1; // Map Request Authoritative bit
break;
case 'o':
probe = 1; // RLOC Probe bit
break;
case 'q':
smr = 1; // SMR bit
break;
case 'n':
smri = 1; // SMR-invoked bit
break;
case 'l':
encapsulate = 0;
break;
case 'v':
fprintf(stderr, VERSION, argv[0]);
exit (GOOD);
default:
fprintf(stderr, USAGE, argv[0]);
exit (BAD);
}
}
/*
* Map register
*/
if(mreg == 1) {
if (src_ip_addr) { //use the source address specified
src_addrtype = get_afi(src_ip_addr); //in the commandline
if (src_addrtype == AF_INET) {
if (get_lisp_addr_from_char(src_ip_addr, default_ctrl_iface_v4->ipv4_address) == BAD) {
lispd_log_msg(LISP_LOG_ERR, "source_ipv4");
}
}
else {
if (get_lisp_addr_from_char(src_ip_addr, default_ctrl_iface_v6->ipv6_address) == BAD) {
lispd_log_msg(LISP_LOG_ERR, "source_ipv6");
}
}
}
if(add_map_server(map_server_addr, 1, pass, proxy) == BAD) { // add the map server entry to the list
lispd_log_msg(LISP_LOG_ERR, "new_map_server");
exit(BAD);
}
if(map_register(mapping) != GOOD) {
lispd_log_msg(LISP_LOG_ERR, "Couldn't send map register");
exit(BAD);
}
printf("\nSent Map-Register to %s for %s/%d\n\n", map_server_addr, eidpref, eid_prefix_length);
exit(GOOD);
}
/*
* save the program name somewhere
*/
if ((progname = strdup(argv[0])) == NULL) {
perror ("strdup");
exit(BAD);
}
argc -= optind;
argv += optind;
if (argc != 1) {
fprintf(stderr, USAGE, progname);
exit (BAD);
}
/*
* The requested eid should be in argv[0]
*/
/*
* start skip if map register
*
*/
if (mreg == 0) {
if ((eid = strdup(argv[0])) == NULL) {
perror ("strdup(argv[0])");
exit(BAD);
}
if ((eid_name = strdup(eid)) == NULL) {
perror ("strdup(eid)");
exit(BAD);
}
if (map_resolver == NULL) {
fprintf(stderr,
"%s not set and -m not specified\n",
LISP_MAP_RESOLVER);
fprintf(stderr, USAGE, progname);
exit(BAD);
}
if ((mr_name = strdup(map_resolver)) == NULL) {
perror ("strdup(map_resolver)");
exit(BAD);
}
/*
* We'll use getaddrinfo() for name lookups.
* Explicitly set options by setting up a non-NULL hints
*/
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
hints.ai_flags = AI_ADDRCONFIG; /* Only return families configured on host */
hints.ai_protocol = 0; /* Any protocol */
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
if ((e = getaddrinfo(eid_name, NULL, &hints, &res)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
exit(BAD);
}
if (res != NULL) {
if ((e = getnameinfo(res->ai_addr,res->ai_addrlen,
buf,NI_MAXHOST,NULL,0,NI_NUMERICHOST)) != 0) {
fprintf(stderr,"getnameinfo: %s\n",gai_strerror(e));
exit(BAD);
}
eid = strdup(buf);
memcpy(&eid_addr, res->ai_addr, res->ai_addrlen);
}
freeaddrinfo(res);
/*
* likewise for the map resolver
*/
if ((e = getaddrinfo(map_resolver, LISP_CONTROL_PORT_STR, &hints, &res)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
exit(BAD);
}
if (res != NULL) {
mr_addrtype = res->ai_family;
mr_length = res->ai_addrlen;
if ((e = getnameinfo(res->ai_addr,res->ai_addrlen,
buf,NI_MAXHOST,NULL,0,NI_NUMERICHOST)) != 0) {
fprintf(stderr,"getnameinfo: %s\n",gai_strerror(e));
exit(BAD);
}
map_resolver = strdup(buf);
memcpy(&map_resolver_addr, res->ai_addr, res->ai_addrlen);
}
freeaddrinfo(res);
/*
* get an array of nonces of size 2*count
* (need 2*count as nonces are 64 bit as of
* draft-ietf-lisp-04.txt)
*/
if ((nonce = (unsigned int *) malloc(2*count*sizeof(unsigned int))) < 0) {
perror ("malloc (nonce)");
exit(BAD);
}
if ((proto = getprotobyname("UDP")) == NULL) {
perror ("getprotobyname");
exit(BAD);
}
if (src_ip_addr) {
if ((e = getaddrinfo(src_ip_addr, NULL, &hints, &res)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
exit(BAD);
}
memcpy(&my_addr, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res);
} else{
if (get_my_ip_addr(mr_addrtype,&my_addr)) {
fprintf(stderr, "No usable %s source address\n",
(mr_addrtype == AF_INET) ? "IPv4" : "IPv6");
exit(BAD);
}
}
if (src_eid_addr) {
if ((e = getaddrinfo(src_eid_addr, NULL, &hints, &res)) != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(e));
exit(BAD);
}
memcpy(&src_eid, res->ai_addr, res->ai_addrlen);
freeaddrinfo(res);
src_eid_ptr = (struct sockaddr *)&src_eid;
}
if (debug) {
if ((e = getnameinfo((struct sockaddr *)&my_addr,SA_LEN(my_addr.ss_family),
buf,NI_MAXHOST,NULL,0,NI_NUMERICHOST)) != 0) {
fprintf(stderr,"getnameinfo: %s\n",gai_strerror(e));
exit(BAD);
}
printf("Using source address (ITR-RLOC) %s\n", buf);
}
/*
* Initialize the random number generator for the nonces
*/
iseed = (unsigned int) time (NULL);
srandom(iseed);
/*
* http://tools.ietf.org/html/draft-larsen-tsvwg-port-randomization-02.txt
*/
if (!emr_inner_src_port)
emr_inner_src_port = MIN_EPHEMERAL_PORT +
random() % (MAX_EPHEMERAL_PORT - MIN_EPHEMERAL_PORT);
memset(packet, 0, MAX_IP_PACKET);
ctrl_socket = open_udp_socket(mr_addrtype);
if (ctrl_socket == BAD){
perror("socket_creation:");
exit(BAD);
}
if ( (ctrl_socket = bind_socket(ctrl_socket,mr_addrtype,4342)) == BAD){
perror("bind");
exit(BAD);
}
for (i = 0; i < count; i++) {
build_nonce(nonce,i,&nonce0,&nonce1);
if (debug) {
if ((e = getnameinfo((struct sockaddr *)(&map_resolver_addr), mr_length,
buf,NI_MAXHOST,NULL,0,NI_NUMERICHOST)) != 0) {
fprintf(stderr,"getnameinfo: %s\n",gai_strerror(e));
exit(BAD);
}
if (encapsulate == 1){
printf("Send encapsulated map-request to %s (%s) for %s (%s) ...\n",
mr_name,
buf,
eid_name,
eid);
}
else {
printf("Send map-request to %s (%s) for %s (%s) ...\n",
mr_name,
buf,
eid_name,
eid);
}
} else if (machinereadable && i == 0) {
printf("MAPRESOLVER=%s\nEID=%s\n", mr_name, eid_name);
}
else if (!machinereadable){
if (encapsulate == 1) {
printf("Send encapsulated map-request to %s for %s ...\n", mr_name, eid_name);
}
else {
printf("Send map-request to %s for %s ...\n", mr_name, eid_name);
}
}
if (send_map_request(ctrl_socket,
nonce0,
nonce1,
&before,
(struct sockaddr *)&eid_addr,
(struct sockaddr *)&map_resolver_addr,
(struct sockaddr *)&my_addr,
src_eid_ptr,
encapsulate) == BAD) {
fprintf(stderr, "send_map_request: can't send map-request\n");
exit(BAD);
}
if (wait_for_reply == FALSE){
exit(GOOD);
}
recv_packet:
if (wait_for_response(ctrl_socket,timeout)) {
if (gettimeofday(&after,NULL) == -1) {
perror("gettimeofday");
return(BAD);
}
if (!get_map_reply(ctrl_socket, packet, mr_addrtype, &from)){
continue; /* try again if count left */
}
map_reply = (struct map_reply_pkt *) packet;
if ((e = getnameinfo((struct sockaddr *)&from,SA_LEN(from.ss_family),
buf,NI_MAXHOST,NULL,0,NI_NUMERICHOST)) != 0) {
fprintf(stderr,"getnameinfo: %s\n",gai_strerror(e));
exit(BAD);
}
if (find_nonce(map_reply,nonce, (i+1))) {
print_map_reply(map_reply,
eid,
map_resolver,
strdup(buf),
tvdiff(&after,&before),
machinereadable);
exit(GOOD);
} else { /* Otherwise assume its spoofed */
printf("Spoofed map-reply: 0x%08x/0x%08x-0x%08x/0x%08x\n",
nonce0,
ntohl(map_reply->lisp_nonce0),
nonce1,
ntohl(map_reply->lisp_nonce1));
goto recv_packet;
}
} /* timed out */
}
printf("*** No map-reply received ***\n");
exit(GOOD);
}
/*
* end skip if map register
*
*/
exit(GOOD);
}
void set_locator_defaults(
uint8_t *priority,
uint8_t *weight,
uint8_t *mpriority,
uint8_t *mweight,
uint8_t *reach)
{
*priority = 1;
*weight = 100;
*mpriority = 1;
*mweight = 100;
*reach = UP;
}