rrenumd.c (9a4365d0e0833374e893c519639bde71756aa104) | rrenumd.c (434d523b2d63281f9daf43fddcb5f009ac54800c) |
---|---|
1/* $KAME$ */ 2 |
|
1/* 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 30 unchanged lines hidden (view full) --- 39#include <net/route.h> 40 41#include <netinet/in_systm.h> 42#include <netinet/in.h> 43#include <netinet/ip.h> 44#include <netinet/ip6.h> 45#include <netinet/icmp6.h> 46 | 3/* 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright --- 30 unchanged lines hidden (view full) --- 41#include <net/route.h> 42 43#include <netinet/in_systm.h> 44#include <netinet/in.h> 45#include <netinet/ip.h> 46#include <netinet/ip6.h> 47#include <netinet/icmp6.h> 48 |
49#include <arpa/inet.h> 50 |
|
47#ifdef IPSEC 48#include <netinet6/ipsec.h> 49#endif 50 51#include <stdio.h> | 51#ifdef IPSEC 52#include <netinet6/ipsec.h> 53#endif 54 55#include <stdio.h> |
56#include <err.h> |
|
52#include <errno.h> 53#include <stdlib.h> 54#include <unistd.h> 55#include <syslog.h> 56 57#include "rrenumd.h" 58 | 57#include <errno.h> 58#include <stdlib.h> 59#include <unistd.h> 60#include <syslog.h> 61 62#include "rrenumd.h" 63 |
59#define LL_ALLROUTERS "ff02::2" 60#define SL_ALLROUTERS "ff05::2" | 64#define LL_ALLROUTERS "ff02::2" 65#define SL_ALLROUTERS "ff05::2" |
61 62#ifndef IN6_IS_SCOPE_LINKLOCAL | 66 67#ifndef IN6_IS_SCOPE_LINKLOCAL |
63#define IN6_IS_SCOPE_LINKLOCAL(a) \ | 68#define IN6_IS_SCOPE_LINKLOCAL(a) \ |
64 ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 65 (IN6_IS_ADDR_MC_LINKLOCAL(a))) 66#endif /* IN6_IS_SCOPE_LINKLOCAL */ 67 68struct flags { | 69 ((IN6_IS_ADDR_LINKLOCAL(a)) || \ 70 (IN6_IS_ADDR_MC_LINKLOCAL(a))) 71#endif /* IN6_IS_SCOPE_LINKLOCAL */ 72 73struct flags { |
69 u_long debug : 1; 70 u_long fg : 1; | 74 u_long debug : 1; 75 u_long fg : 1; |
71#ifdef IPSEC 72#ifdef IPSEC_POLICY_IPSEC | 76#ifdef IPSEC 77#ifdef IPSEC_POLICY_IPSEC |
73 u_long policy : 1; | 78 u_long policy : 1; 79#else /* IPSEC_POLICY_IPSEC */ 80 u_long auth : 1; 81 u_long encrypt : 1; |
74#endif /* IPSEC_POLICY_IPSEC */ 75#endif /*IPSEC*/ 76}; 77 | 82#endif /* IPSEC_POLICY_IPSEC */ 83#endif /*IPSEC*/ 84}; 85 |
78struct msghdr sndmhdr; 79struct msghdr rcvmhdr; 80struct sockaddr_in6 from; 81struct sockaddr_in6 sin6_ll_allrouters; | 86struct msghdr sndmhdr; 87struct msghdr rcvmhdr; 88struct sockaddr_in6 from; 89struct sockaddr_in6 sin6_ll_allrouters; |
82 | 90 |
83int s6; 84int with_v6dest; 85struct in6_addr prefix; /* ADHOC */ 86int prefixlen = 64; /* ADHOC */ | 91int s4, s6; 92int with_v4dest, with_v6dest; 93struct in6_addr prefix; /* ADHOC */ 94int prefixlen = 64; /* ADHOC */ |
87 | 95 |
88extern int parse(FILE **fp); | 96extern int parse(FILE **fp); |
89 90/* Print usage. Don't call this after daemonized. */ 91static void 92show_usage() 93{ 94 fprintf(stderr, "usage: rrenumd [-c conf_file|-s] [-df" 95#ifdef IPSEC 96#ifdef IPSEC_POLICY_IPSEC 97 "] [-P policy" | 97 98/* Print usage. Don't call this after daemonized. */ 99static void 100show_usage() 101{ 102 fprintf(stderr, "usage: rrenumd [-c conf_file|-s] [-df" 103#ifdef IPSEC 104#ifdef IPSEC_POLICY_IPSEC 105 "] [-P policy" |
106#else /* IPSEC_POLICY_IPSEC */ 107 "AE" |
|
98#endif /* IPSEC_POLICY_IPSEC */ 99#endif /* IPSEC */ 100 "]\n"); 101 exit(1); 102} 103 104void 105init_sin6(struct sockaddr_in6 *sin6, const char *addr_ascii) 106{ 107 memset(sin6, 0, sizeof(*sin6)); 108 sin6->sin6_len = sizeof(*sin6); 109 sin6->sin6_family = AF_INET6; 110 if (inet_pton(AF_INET6, addr_ascii, &sin6->sin6_addr) != 1) 111 ; /* XXX do something */ 112} 113 | 108#endif /* IPSEC_POLICY_IPSEC */ 109#endif /* IPSEC */ 110 "]\n"); 111 exit(1); 112} 113 114void 115init_sin6(struct sockaddr_in6 *sin6, const char *addr_ascii) 116{ 117 memset(sin6, 0, sizeof(*sin6)); 118 sin6->sin6_len = sizeof(*sin6); 119 sin6->sin6_family = AF_INET6; 120 if (inet_pton(AF_INET6, addr_ascii, &sin6->sin6_addr) != 1) 121 ; /* XXX do something */ 122} 123 |
124#if 0 /* XXX: not necessary ?? */ |
|
114void | 125void |
126join_multi(const char *addrname) 127{ 128 struct ipv6_mreq mreq; 129 130 if (inet_pton(AF_INET6, addrname, &mreq.ipv6mr_multiaddr.s6_addr) 131 != 1) { 132 syslog(LOG_ERR, "<%s> inet_pton failed(library bug?)", 133 __FUNCTION__); 134 exit(1); 135 } 136 /* ADHOC: currently join only one */ 137 { 138 if ((mreq.ipv6mr_interface = if_nametoindex(ifname)) == 0) { 139 syslog(LOG_ERR, "<%s> ifname %s should be invalid: %s", 140 __FUNCTION__, ifname, strerror(errno)); 141 exit(1); 142 } 143 if (setsockopt(s, IPPROTO_IPV6, IPV6_JOIN_GROUP, 144 &mreq, 145 sizeof(mreq)) < 0) { 146 syslog(LOG_ERR, "<%s> IPV6_JOIN_GROUP on %s: %s", 147 __FUNCTION__, ifname, strerror(errno)); 148 exit(1); 149 } 150 } 151} 152#endif 153 154void |
|
115init_globals() 116{ 117 static struct iovec rcviov; 118 static u_char rprdata[4500]; /* maximal MTU of connected links */ | 155init_globals() 156{ 157 static struct iovec rcviov; 158 static u_char rprdata[4500]; /* maximal MTU of connected links */ |
119 static u_char rcvcmsgbuf[CMSG_SPACE(sizeof(struct in6_pktinfo)) + 120 CMSG_SPACE(sizeof(int))]; 121 static u_char sndcmsgbuf[CMSG_SPACE(sizeof(struct in6_pktinfo)) + 122 CMSG_SPACE(sizeof(int))]; | 159 static u_char *rcvcmsgbuf = NULL; 160 static u_char *sndcmsgbuf = NULL; 161 int sndcmsglen, rcvcmsglen; |
123 124 /* init ll_allrouters */ 125 init_sin6(&sin6_ll_allrouters, LL_ALLROUTERS); 126 127 /* initialize msghdr for receiving packets */ 128 rcviov.iov_base = (caddr_t)rprdata; 129 rcviov.iov_len = sizeof(rprdata); 130 rcvmhdr.msg_namelen = sizeof(struct sockaddr_in6); 131 rcvmhdr.msg_iov = &rcviov; 132 rcvmhdr.msg_iovlen = 1; | 162 163 /* init ll_allrouters */ 164 init_sin6(&sin6_ll_allrouters, LL_ALLROUTERS); 165 166 /* initialize msghdr for receiving packets */ 167 rcviov.iov_base = (caddr_t)rprdata; 168 rcviov.iov_len = sizeof(rprdata); 169 rcvmhdr.msg_namelen = sizeof(struct sockaddr_in6); 170 rcvmhdr.msg_iov = &rcviov; 171 rcvmhdr.msg_iovlen = 1; |
172 rcvcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + 173 CMSG_SPACE(sizeof(int)); 174 if (rcvcmsgbuf == NULL && 175 (rcvcmsgbuf = (u_char *)malloc(rcvcmsglen)) == NULL) { 176 syslog(LOG_ERR, "<%s>: malloc failed", __FUNCTION__); 177 exit(1); 178 } |
|
133 rcvmhdr.msg_control = (caddr_t)rcvcmsgbuf; | 179 rcvmhdr.msg_control = (caddr_t)rcvcmsgbuf; |
134 rcvmhdr.msg_controllen = sizeof(rcvcmsgbuf); | 180 rcvmhdr.msg_controllen = rcvcmsglen; |
135 136 /* initialize msghdr for sending packets */ 137 sndmhdr.msg_namelen = sizeof(struct sockaddr_in6); 138 sndmhdr.msg_iovlen = 1; | 181 182 /* initialize msghdr for sending packets */ 183 sndmhdr.msg_namelen = sizeof(struct sockaddr_in6); 184 sndmhdr.msg_iovlen = 1; |
185 sndcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) + 186 CMSG_SPACE(sizeof(int)); 187 if (sndcmsgbuf == NULL && 188 (sndcmsgbuf = (u_char *)malloc(sndcmsglen)) == NULL) { 189 syslog(LOG_ERR, "<%s>: malloc failed", __FUNCTION__); 190 exit(1); 191 } |
|
139 sndmhdr.msg_control = (caddr_t)sndcmsgbuf; | 192 sndmhdr.msg_control = (caddr_t)sndcmsgbuf; |
140 sndmhdr.msg_controllen = sizeof(sndcmsgbuf); | 193 sndmhdr.msg_controllen = sndcmsglen; |
141} 142 143void 144config(FILE **fpp) 145{ 146 struct payload_list *pl; 147 struct iovec *iov; 148 struct icmp6_router_renum *irr; --- 37 unchanged lines hidden (view full) --- 186void 187sock6_open(struct flags *flags 188#ifdef IPSEC_POLICY_IPSEC 189 , char *policy 190#endif /* IPSEC_POLICY_IPSEC */ 191 ) 192{ 193 struct icmp6_filter filt; | 194} 195 196void 197config(FILE **fpp) 198{ 199 struct payload_list *pl; 200 struct iovec *iov; 201 struct icmp6_router_renum *irr; --- 37 unchanged lines hidden (view full) --- 239void 240sock6_open(struct flags *flags 241#ifdef IPSEC_POLICY_IPSEC 242 , char *policy 243#endif /* IPSEC_POLICY_IPSEC */ 244 ) 245{ 246 struct icmp6_filter filt; |
194 int on, optval; | 247 int on; 248#ifdef IPSEC 249#ifndef IPSEC_POLICY_IPSEC 250 int optval; 251#endif 252#endif |
195 196 if (with_v6dest == 0) 197 return; 198 if (with_v6dest && 199 (s6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) { 200 syslog(LOG_ERR, "<%s> socket(v6): %s", __FUNCTION__, 201 strerror(errno)); 202 exit(1); 203 } 204 | 253 254 if (with_v6dest == 0) 255 return; 256 if (with_v6dest && 257 (s6 = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0) { 258 syslog(LOG_ERR, "<%s> socket(v6): %s", __FUNCTION__, 259 strerror(errno)); 260 exit(1); 261 } 262 |
205 /* join all routers multicast addresses, not necessary? */ | 263 /* 264 * join all routers multicast addresses. 265 */ 266#if 0 /* XXX: not necessary ?? */ 267 join_multi(LL_ALLROUTERS); 268 join_multi(SL_ALLROUTERS); 269#endif |
206 207 /* set icmpv6 filter */ 208 ICMP6_FILTER_SETBLOCKALL(&filt); 209 ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING, &filt); 210 if (setsockopt(s6, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, 211 sizeof(filt)) < 0) { 212 syslog(LOG_ERR, "<%s> IICMP6_FILTER: %s", 213 __FUNCTION__, strerror(errno)); --- 17 unchanged lines hidden (view full) --- 231 if (buf == NULL) 232 errx(1, ipsec_strerror()); 233 /* XXX should handle in/out bound policy. */ 234 if (setsockopt(s6, IPPROTO_IPV6, IPV6_IPSEC_POLICY, 235 buf, ipsec_get_policylen(buf)) < 0) 236 err(1, NULL); 237 free(buf); 238 } | 270 271 /* set icmpv6 filter */ 272 ICMP6_FILTER_SETBLOCKALL(&filt); 273 ICMP6_FILTER_SETPASS(ICMP6_ROUTER_RENUMBERING, &filt); 274 if (setsockopt(s6, IPPROTO_ICMPV6, ICMP6_FILTER, &filt, 275 sizeof(filt)) < 0) { 276 syslog(LOG_ERR, "<%s> IICMP6_FILTER: %s", 277 __FUNCTION__, strerror(errno)); --- 17 unchanged lines hidden (view full) --- 295 if (buf == NULL) 296 errx(1, ipsec_strerror()); 297 /* XXX should handle in/out bound policy. */ 298 if (setsockopt(s6, IPPROTO_IPV6, IPV6_IPSEC_POLICY, 299 buf, ipsec_get_policylen(buf)) < 0) 300 err(1, NULL); 301 free(buf); 302 } |
303#else /* IPSEC_POLICY_IPSEC */ 304 if (flags->auth) { 305 optval = IPSEC_LEVEL_REQUIRE; 306 if (setsockopt(s6, IPPROTO_IPV6, IPV6_AUTH_TRANS_LEVEL, 307 &optval, sizeof(optval)) == -1) { 308 syslog(LOG_ERR, "<%s> IPV6_AUTH_TRANS_LEVEL: %s", 309 __FUNCTION__, strerror(errno)); 310 exit(1); 311 } 312 } 313 if (flags->encrypt) { 314 optval = IPSEC_LEVEL_REQUIRE; 315 if (setsockopt(s6, IPPROTO_IPV6, IPV6_ESP_TRANS_LEVEL, 316 &optval, sizeof(optval)) == -1) { 317 syslog(LOG_ERR, "<%s> IPV6_ESP_TRANS_LEVEL: %s", 318 __FUNCTION__, strerror(errno)); 319 exit(1); 320 } 321 } |
|
239#endif /* IPSEC_POLICY_IPSEC */ 240#endif /* IPSEC */ 241 242 return; 243} 244 245void | 322#endif /* IPSEC_POLICY_IPSEC */ 323#endif /* IPSEC */ 324 325 return; 326} 327 328void |
329sock4_open(struct flags *flags 330#ifdef IPSEC_POLICY_IPSEC 331 , char *policy 332#endif /* IPSEC_POLICY_IPSEC */ 333 ) 334{ 335#ifdef IPSEC 336#ifndef IPSEC_POLICY_IPSEC 337 int optval; 338#endif 339#endif 340 341 if (with_v4dest == 0) 342 return; 343 if ((s4 = socket(AF_INET, SOCK_RAW, IPPROTO_ICMPV6)) < 0) { 344 syslog(LOG_ERR, "<%s> socket(v4): %s", __FUNCTION__, 345 strerror(errno)); 346 exit(1); 347 } 348 349#if 0 /* XXX: not necessary ?? */ 350 /* 351 * join all routers multicast addresses. 352 */ 353 some_join_function(); 354#endif 355 356#ifdef IPSEC 357#ifdef IPSEC_POLICY_IPSEC 358 if (flags->policy) { 359 char *buf; 360 buf = ipsec_set_policy(policy, strlen(policy)); 361 if (buf == NULL) 362 errx(1, ipsec_strerror()); 363 /* XXX should handle in/out bound policy. */ 364 if (setsockopt(s4, IPPROTO_IP, IP_IPSEC_POLICY, 365 buf, ipsec_get_policylen(buf)) < 0) 366 err(1, NULL); 367 free(buf); 368 } 369#else /* IPSEC_POLICY_IPSEC */ 370 if (flags->auth) { 371 optval = IPSEC_LEVEL_REQUIRE; 372 if (setsockopt(s4, IPPROTO_IP, IP_AUTH_TRANS_LEVEL, 373 &optval, sizeof(optval)) == -1) { 374 syslog(LOG_ERR, "<%s> IP_AUTH_TRANS_LEVEL: %s", 375 __FUNCTION__, strerror(errno)); 376 exit(1); 377 } 378 } 379 if (flags->encrypt) { 380 optval = IPSEC_LEVEL_REQUIRE; 381 if (setsockopt(s4, IPPROTO_IP, IP_ESP_TRANS_LEVEL, 382 &optval, sizeof(optval)) == -1) { 383 syslog(LOG_ERR, "<%s> IP_ESP_TRANS_LEVEL: %s", 384 __FUNCTION__, strerror(errno)); 385 exit(1); 386 } 387 } 388#endif /* IPSEC_POLICY_IPSEC */ 389#endif /* IPSEC */ 390 391 return; 392} 393 394void |
|
246rrenum_output(struct payload_list *pl, struct dst_list *dl) 247{ 248 int i, msglen = 0; 249 struct cmsghdr *cm; 250 struct in6_pktinfo *pi; | 395rrenum_output(struct payload_list *pl, struct dst_list *dl) 396{ 397 int i, msglen = 0; 398 struct cmsghdr *cm; 399 struct in6_pktinfo *pi; |
251 struct icmp6_router_renum *rr; | |
252 struct sockaddr_in6 *sin6 = NULL; 253 254 sndmhdr.msg_name = (caddr_t)dl->dl_dst; 255 if (dl->dl_dst->sa_family == AF_INET6) 256 sin6 = (struct sockaddr_in6 *)dl->dl_dst; 257 258 if (sin6 != NULL && 259 IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) { 260 int hoplimit = 255; 261 262 cm = CMSG_FIRSTHDR(&sndmhdr); 263 /* specify the outgoing interface */ 264 cm->cmsg_level = IPPROTO_IPV6; 265 cm->cmsg_type = IPV6_PKTINFO; 266 cm->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo)); 267 pi = (struct in6_pktinfo *)CMSG_DATA(cm); 268 memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*XXX*/ 269 pi->ipi6_ifindex = sin6->sin6_scope_id; | 400 struct sockaddr_in6 *sin6 = NULL; 401 402 sndmhdr.msg_name = (caddr_t)dl->dl_dst; 403 if (dl->dl_dst->sa_family == AF_INET6) 404 sin6 = (struct sockaddr_in6 *)dl->dl_dst; 405 406 if (sin6 != NULL && 407 IN6_IS_SCOPE_LINKLOCAL(&sin6->sin6_addr)) { 408 int hoplimit = 255; 409 410 cm = CMSG_FIRSTHDR(&sndmhdr); 411 /* specify the outgoing interface */ 412 cm->cmsg_level = IPPROTO_IPV6; 413 cm->cmsg_type = IPV6_PKTINFO; 414 cm->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo)); 415 pi = (struct in6_pktinfo *)CMSG_DATA(cm); 416 memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*XXX*/ 417 pi->ipi6_ifindex = sin6->sin6_scope_id; |
270 msglen += CMSG_SPACE(sizeof(struct in6_pktinfo)); | 418 msglen += CMSG_LEN(sizeof(struct in6_pktinfo)); |
271 272 /* specify the hop limit of the packet if dest is link local */ 273 /* not defined by router-renum-05.txt, but maybe its OK */ 274 cm = CMSG_NXTHDR(&sndmhdr, cm); 275 cm->cmsg_level = IPPROTO_IPV6; 276 cm->cmsg_type = IPV6_HOPLIMIT; 277 cm->cmsg_len = CMSG_LEN(sizeof(int)); 278 memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int)); | 419 420 /* specify the hop limit of the packet if dest is link local */ 421 /* not defined by router-renum-05.txt, but maybe its OK */ 422 cm = CMSG_NXTHDR(&sndmhdr, cm); 423 cm->cmsg_level = IPPROTO_IPV6; 424 cm->cmsg_type = IPV6_HOPLIMIT; 425 cm->cmsg_len = CMSG_LEN(sizeof(int)); 426 memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int)); |
279 msglen += CMSG_SPACE(sizeof(int)); | 427 msglen += CMSG_LEN(sizeof(int)); |
280 } 281 sndmhdr.msg_controllen = msglen; 282 if (sndmhdr.msg_controllen == 0) 283 sndmhdr.msg_control = 0; 284 285 sndmhdr.msg_iov = &pl->pl_sndiov; | 428 } 429 sndmhdr.msg_controllen = msglen; 430 if (sndmhdr.msg_controllen == 0) 431 sndmhdr.msg_control = 0; 432 433 sndmhdr.msg_iov = &pl->pl_sndiov; |
286 i = sendmsg(s6, &sndmhdr, 0); | 434 i = sendmsg(dl->dl_dst->sa_family == AF_INET ? s4 : s6, &sndmhdr, 0); |
287 288 if (i < 0 || i != sndmhdr.msg_iov->iov_len) 289 syslog(LOG_ERR, "<%s> sendmsg: %s", __FUNCTION__, 290 strerror(errno)); 291} 292 293void 294rrenum_snd_eachdst(struct payload_list *pl) --- 22 unchanged lines hidden (view full) --- 317 struct icmp6_router_renum *rr; 318 319 /* get message */ 320 if ((i = recvmsg(s, &rcvmhdr, 0)) < 0) { 321 syslog(LOG_ERR, "<%s> recvmsg: %s", __FUNCTION__, 322 strerror(errno)); 323 return; 324 } | 435 436 if (i < 0 || i != sndmhdr.msg_iov->iov_len) 437 syslog(LOG_ERR, "<%s> sendmsg: %s", __FUNCTION__, 438 strerror(errno)); 439} 440 441void 442rrenum_snd_eachdst(struct payload_list *pl) --- 22 unchanged lines hidden (view full) --- 465 struct icmp6_router_renum *rr; 466 467 /* get message */ 468 if ((i = recvmsg(s, &rcvmhdr, 0)) < 0) { 469 syslog(LOG_ERR, "<%s> recvmsg: %s", __FUNCTION__, 470 strerror(errno)); 471 return; 472 } |
473 if (s == s4) 474 i -= sizeof(struct ip); |
|
325 if (i < sizeof(struct icmp6_router_renum)) { 326 syslog(LOG_ERR, "<%s> packet size(%d) is too short", 327 __FUNCTION__, i); 328 return; 329 } | 475 if (i < sizeof(struct icmp6_router_renum)) { 476 syslog(LOG_ERR, "<%s> packet size(%d) is too short", 477 __FUNCTION__, i); 478 return; 479 } |
330 rr = (struct icmp6_router_renum *)rcvmhdr.msg_iov->iov_base; | 480 if (s == s4) { 481 struct ip *ip = (struct ip *)rcvmhdr.msg_iov->iov_base; |
331 | 482 |
483 rr = (struct icmp6_router_renum *)(ip + 1); 484 } else /* s == s6 */ 485 rr = (struct icmp6_router_renum *)rcvmhdr.msg_iov->iov_base; 486 |
|
332 switch(rr->rr_code) { 333 case ICMP6_ROUTER_RENUMBERING_COMMAND: 334 /* COMMAND will be processed by rtadvd */ 335 break; 336 case ICMP6_ROUTER_RENUMBERING_RESULT: 337 /* TODO: receiving result message */ 338 break; 339 default: | 487 switch(rr->rr_code) { 488 case ICMP6_ROUTER_RENUMBERING_COMMAND: 489 /* COMMAND will be processed by rtadvd */ 490 break; 491 case ICMP6_ROUTER_RENUMBERING_RESULT: 492 /* TODO: receiving result message */ 493 break; 494 default: |
340 syslog(LOG_ERR, "<%s> received unknown code %d" | 495 syslog(LOG_ERR, "<%s> received unknown code %d", |
341 __FUNCTION__, rr->rr_code); 342 break; 343 } 344} 345 346int 347main(int argc, char *argv[]) 348{ | 496 __FUNCTION__, rr->rr_code); 497 break; 498 } 499} 500 501int 502main(int argc, char *argv[]) 503{ |
349 char *cfile = NULL; | |
350 FILE *fp = stdin; 351 fd_set fdset; 352 struct timeval timeout; 353 int ch, i, maxfd = 0, send_counter = 0; 354 struct flags flags; 355 struct payload_list *pl; 356#ifdef IPSEC_POLICY_IPSEC 357 char *policy = NULL; 358#endif 359 360 memset(&flags, 0, sizeof(flags)); | 504 FILE *fp = stdin; 505 fd_set fdset; 506 struct timeval timeout; 507 int ch, i, maxfd = 0, send_counter = 0; 508 struct flags flags; 509 struct payload_list *pl; 510#ifdef IPSEC_POLICY_IPSEC 511 char *policy = NULL; 512#endif 513 514 memset(&flags, 0, sizeof(flags)); |
361 openlog(*argv, LOG_PID, LOG_DAEMON); | 515 openlog("rrenumd", LOG_PID, LOG_DAEMON); |
362 363 /* get options */ 364 while ((ch = getopt(argc, argv, "c:sdf" 365#ifdef IPSEC 366#ifdef IPSEC_POLICY_IPSEC | 516 517 /* get options */ 518 while ((ch = getopt(argc, argv, "c:sdf" 519#ifdef IPSEC 520#ifdef IPSEC_POLICY_IPSEC |
367 "P:" | 521 "P" 522#else /* IPSEC_POLICY_IPSEC */ 523 "AE" |
368#endif /* IPSEC_POLICY_IPSEC */ 369#endif /* IPSEC */ 370 )) != -1){ 371 switch (ch) { 372 case 'c': 373 if((fp = fopen(optarg, "r")) == NULL) { 374 syslog(LOG_ERR, 375 "<%s> config file %s open failed", --- 11 unchanged lines hidden (view full) --- 387 flags.fg = 1; 388 break; 389#ifdef IPSEC 390#ifdef IPSEC_POLICY_IPSEC 391 case 'P': 392 flags.policy = 1; 393 policy = strdup(optarg); 394 break; | 524#endif /* IPSEC_POLICY_IPSEC */ 525#endif /* IPSEC */ 526 )) != -1){ 527 switch (ch) { 528 case 'c': 529 if((fp = fopen(optarg, "r")) == NULL) { 530 syslog(LOG_ERR, 531 "<%s> config file %s open failed", --- 11 unchanged lines hidden (view full) --- 543 flags.fg = 1; 544 break; 545#ifdef IPSEC 546#ifdef IPSEC_POLICY_IPSEC 547 case 'P': 548 flags.policy = 1; 549 policy = strdup(optarg); 550 break; |
551#else /* IPSEC_POLICY_IPSEC */ 552 case 'A': 553 flags.auth = 1; 554 break; 555 case 'E': 556 flags.encrypt = 1; 557 break; |
|
395#endif /* IPSEC_POLICY_IPSEC */ 396#endif /*IPSEC*/ 397 default: 398 show_usage(); 399 } 400 } 401 argc -= optind; 402 argv += optind; --- 9 unchanged lines hidden (view full) --- 412 413 config(&fp); 414 415 sock6_open(&flags 416#ifdef IPSEC_POLICY_IPSEC 417 , policy 418#endif /* IPSEC_POLICY_IPSEC */ 419 ); | 558#endif /* IPSEC_POLICY_IPSEC */ 559#endif /*IPSEC*/ 560 default: 561 show_usage(); 562 } 563 } 564 argc -= optind; 565 argv += optind; --- 9 unchanged lines hidden (view full) --- 575 576 config(&fp); 577 578 sock6_open(&flags 579#ifdef IPSEC_POLICY_IPSEC 580 , policy 581#endif /* IPSEC_POLICY_IPSEC */ 582 ); |
583 sock4_open(&flags 584#ifdef IPSEC_POLICY_IPSEC 585 , policy 586#endif /* IPSEC_POLICY_IPSEC */ 587 ); |
|
420 421 if (!flags.fg) 422 daemon(0, 0); 423 424 FD_ZERO(&fdset); 425 if (with_v6dest) { 426 FD_SET(s6, &fdset); 427 if (s6 > maxfd) 428 maxfd = s6; 429 } | 588 589 if (!flags.fg) 590 daemon(0, 0); 591 592 FD_ZERO(&fdset); 593 if (with_v6dest) { 594 FD_SET(s6, &fdset); 595 if (s6 > maxfd) 596 maxfd = s6; 597 } |
598 if (with_v4dest) { 599 FD_SET(s4, &fdset); 600 if (s4 > maxfd) 601 maxfd = s4; 602 } |
|
430 431 /* ADHOC: timeout each 30seconds */ 432 memset(&timeout, 0, sizeof(timeout)); 433 timeout.tv_sec = 30; 434 435 /* init temporal payload_list and send_counter*/ 436 pl = pl_head; 437 send_counter = retry + 1; --- 11 unchanged lines hidden (view full) --- 449 exit(0); 450 rrenum_snd_eachdst(pl); 451 send_counter--; 452 if (send_counter == 0) { 453 pl = pl->pl_next; 454 send_counter = retry + 1; 455 } 456 } | 603 604 /* ADHOC: timeout each 30seconds */ 605 memset(&timeout, 0, sizeof(timeout)); 606 timeout.tv_sec = 30; 607 608 /* init temporal payload_list and send_counter*/ 609 pl = pl_head; 610 send_counter = retry + 1; --- 11 unchanged lines hidden (view full) --- 622 exit(0); 623 rrenum_snd_eachdst(pl); 624 send_counter--; 625 if (send_counter == 0) { 626 pl = pl->pl_next; 627 send_counter = retry + 1; 628 } 629 } |
630 if (FD_ISSET(s4, &select_fd)) 631 rrenum_input(s4); |
|
457 if (FD_ISSET(s6, &select_fd)) 458 rrenum_input(s6); 459 } 460} | 632 if (FD_ISSET(s6, &select_fd)) 633 rrenum_input(s6); 634 } 635} |