Deleted Added
full compact
rdisc.c (18316) rdisc.c (19880)
1/*
2 * Copyright (c) 1995
3 * The Regents of the University of California. 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

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#if !defined(lint) && !defined(sgi) && !defined(__NetBSD__)
35static char sccsid[] = "@(#)rdisc.c 8.1 (Berkeley) x/y/95";
36#elif defined(__NetBSD__)
37static char rcsid[] = "$NetBSD$";
38#endif
1/*
2 * Copyright (c) 1995
3 * The Regents of the University of California. 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

--- 22 unchanged lines hidden (view full) ---

31 * SUCH DAMAGE.
32 */
33
34#if !defined(lint) && !defined(sgi) && !defined(__NetBSD__)
35static char sccsid[] = "@(#)rdisc.c 8.1 (Berkeley) x/y/95";
36#elif defined(__NetBSD__)
37static char rcsid[] = "$NetBSD$";
38#endif
39#ident "$Revision: 1.16 $"
39#ident "$Revision: 1.17 $"
40
41#include "defs.h"
42#include <netinet/in_systm.h>
43#include <netinet/ip.h>
44#include <netinet/ip_icmp.h>
45
46/* router advertisement ICMP packet */
47struct icmp_ad {

--- 81 unchanged lines hidden (view full) ---

129 for (i = 0; i < p->ad.icmp_ad_num && wp <= lim; i++) {
130 (void)fprintf(ftrace, "\t%s preference=%#x",
131 naddr_ntoa(wp[0]), (int)ntohl(wp[1]));
132 wp += p->ad.icmp_ad_asize;
133 }
134 (void)fputc('\n',ftrace);
135
136 } else {
40
41#include "defs.h"
42#include <netinet/in_systm.h>
43#include <netinet/ip.h>
44#include <netinet/ip_icmp.h>
45
46/* router advertisement ICMP packet */
47struct icmp_ad {

--- 81 unchanged lines hidden (view full) ---

129 for (i = 0; i < p->ad.icmp_ad_num && wp <= lim; i++) {
130 (void)fprintf(ftrace, "\t%s preference=%#x",
131 naddr_ntoa(wp[0]), (int)ntohl(wp[1]));
132 wp += p->ad.icmp_ad_asize;
133 }
134 (void)fputc('\n',ftrace);
135
136 } else {
137 trace_act("%s Router Solic. from %s to %s via %s"
138 " value=%#x\n",
137 trace_act("%s Router Solic. from %s to %s via %s value=%#x",
139 act, naddr_ntoa(from), naddr_ntoa(to),
140 ifp ? ifp->int_name : "?",
141 ntohl(p->so.icmp_so_rsvd));
142 }
143}
144
145/* prepare Router Discovery socket.
146 */

--- 9 unchanged lines hidden (view full) ---

156 }
157}
158
159
160/* Pick multicast group for router-discovery socket
161 */
162void
163set_rdisc_mg(struct interface *ifp,
138 act, naddr_ntoa(from), naddr_ntoa(to),
139 ifp ? ifp->int_name : "?",
140 ntohl(p->so.icmp_so_rsvd));
141 }
142}
143
144/* prepare Router Discovery socket.
145 */

--- 9 unchanged lines hidden (view full) ---

155 }
156}
157
158
159/* Pick multicast group for router-discovery socket
160 */
161void
162set_rdisc_mg(struct interface *ifp,
164 int on) { /* 0=turn it off */
163 int on) /* 0=turn it off */
164{
165 struct ip_mreq m;
166
167 if (rdisc_sock < 0) {
168 /* Create the raw socket so that we can hear at least
169 * broadcast router discovery packets.
170 */
171 if ((ifp->int_state & IS_NO_RDISC) == IS_NO_RDISC
172 || !on)
173 return;
174 get_rdisc_sock();
175 }
176
165 struct ip_mreq m;
166
167 if (rdisc_sock < 0) {
168 /* Create the raw socket so that we can hear at least
169 * broadcast router discovery packets.
170 */
171 if ((ifp->int_state & IS_NO_RDISC) == IS_NO_RDISC
172 || !on)
173 return;
174 get_rdisc_sock();
175 }
176
177 if (!(ifp->int_if_flags & IFF_MULTICAST)
178 || (ifp->int_state & IS_ALIAS)) {
177 if (!(ifp->int_if_flags & IFF_MULTICAST)) {
179 ifp->int_state &= ~(IS_ALL_HOSTS | IS_ALL_ROUTERS);
180 return;
181 }
182
183#ifdef MCAST_PPP_BUG
184 if (ifp->int_if_flags & IFF_POINTOPOINT)
185 return;
186#endif

--- 61 unchanged lines hidden (view full) ---

248set_supplier(void)
249{
250 struct interface *ifp;
251 struct dr *drp;
252
253 if (supplier_set)
254 return;
255
178 ifp->int_state &= ~(IS_ALL_HOSTS | IS_ALL_ROUTERS);
179 return;
180 }
181
182#ifdef MCAST_PPP_BUG
183 if (ifp->int_if_flags & IFF_POINTOPOINT)
184 return;
185#endif

--- 61 unchanged lines hidden (view full) ---

247set_supplier(void)
248{
249 struct interface *ifp;
250 struct dr *drp;
251
252 if (supplier_set)
253 return;
254
256 trace_act("start suppying routes\n");
255 trace_act("start suppying routes");
257
258 /* Forget discovered routes.
259 */
260 for (drp = drs; drp < &drs[MAX_ADS]; drp++) {
261 drp->dr_recv_pref = 0;
262 drp->dr_life = 0;
263 }
264 rdisc_age(0);

--- 57 unchanged lines hidden (view full) ---

322 * to at most SUPPLY_INTERVAL.
323 * This is contrary to RFC 1256, but defends against
324 * black holes.
325 */
326 if (drp->dr_gate == bad_gate) {
327 sec = (now.tv_sec - drp->dr_life
328 + SUPPLY_INTERVAL);
329 if (drp->dr_ts > sec) {
256
257 /* Forget discovered routes.
258 */
259 for (drp = drs; drp < &drs[MAX_ADS]; drp++) {
260 drp->dr_recv_pref = 0;
261 drp->dr_life = 0;
262 }
263 rdisc_age(0);

--- 57 unchanged lines hidden (view full) ---

321 * to at most SUPPLY_INTERVAL.
322 * This is contrary to RFC 1256, but defends against
323 * black holes.
324 */
325 if (drp->dr_gate == bad_gate) {
326 sec = (now.tv_sec - drp->dr_life
327 + SUPPLY_INTERVAL);
328 if (drp->dr_ts > sec) {
330 trace_act("age 0.0.0.0 --> %s"
331 " via %s\n",
329 trace_act("age 0.0.0.0 --> %s via %s",
332 naddr_ntoa(drp->dr_gate),
333 drp->dr_ifp->int_name);
334 drp->dr_ts = sec;
335 }
336 break;
337 }
338 }
339 }

--- 69 unchanged lines hidden (view full) ---

409 }
410
411 /* If that was the last good discovered router on the interface,
412 * then solicit a new one.
413 * This is contrary to RFC 1256, but defends against black holes.
414 */
415 if (i == 0
416 && ifp->int_rdisc_cnt >= MAX_SOLICITATIONS) {
330 naddr_ntoa(drp->dr_gate),
331 drp->dr_ifp->int_name);
332 drp->dr_ts = sec;
333 }
334 break;
335 }
336 }
337 }

--- 69 unchanged lines hidden (view full) ---

407 }
408
409 /* If that was the last good discovered router on the interface,
410 * then solicit a new one.
411 * This is contrary to RFC 1256, but defends against black holes.
412 */
413 if (i == 0
414 && ifp->int_rdisc_cnt >= MAX_SOLICITATIONS) {
417 trace_act("discovered route is bad"
418 "--re-solicit routers via %s\n", ifp->int_name);
415 trace_act("discovered route is bad--re-solicit routers via %s",
416 ifp->int_name);
419 ifp->int_rdisc_cnt = 0;
420 ifp->int_rdisc_timer.tv_sec = 0;
421 rdisc_sol();
422 }
423}
424
425
426/* Find the best discovered route,

--- 54 unchanged lines hidden (view full) ---

481 /* switch to a better default route
482 */
483 if (new_drp != cur_drp) {
484 rt = rtget(RIP_DEFAULT, 0);
485
486 /* Stop using discovered routes if they are all bad
487 */
488 if (new_drp == 0) {
417 ifp->int_rdisc_cnt = 0;
418 ifp->int_rdisc_timer.tv_sec = 0;
419 rdisc_sol();
420 }
421}
422
423
424/* Find the best discovered route,

--- 54 unchanged lines hidden (view full) ---

479 /* switch to a better default route
480 */
481 if (new_drp != cur_drp) {
482 rt = rtget(RIP_DEFAULT, 0);
483
484 /* Stop using discovered routes if they are all bad
485 */
486 if (new_drp == 0) {
489 trace_act("turn off Router Discovery client\n");
487 trace_act("turn off Router Discovery client");
490 rdisc_ok = 0;
491
492 if (rt != 0
493 && (rt->rt_state & RS_RDISC)) {
494 rtchange(rt, rt->rt_state & ~RS_RDISC,
495 rt->rt_gate, rt->rt_router,
496 HOPCNT_INFINITY, 0, rt->rt_ifp,
497 now.tv_sec - GARBAGE_TIME, 0);
498 rtswitch(rt, 0);
499 }
500
501 /* turn on RIP if permitted */
502 rip_on(0);
503
504 } else {
505 if (cur_drp == 0) {
506 trace_act("turn on Router Discovery client"
488 rdisc_ok = 0;
489
490 if (rt != 0
491 && (rt->rt_state & RS_RDISC)) {
492 rtchange(rt, rt->rt_state & ~RS_RDISC,
493 rt->rt_gate, rt->rt_router,
494 HOPCNT_INFINITY, 0, rt->rt_ifp,
495 now.tv_sec - GARBAGE_TIME, 0);
496 rtswitch(rt, 0);
497 }
498
499 /* turn on RIP if permitted */
500 rip_on(0);
501
502 } else {
503 if (cur_drp == 0) {
504 trace_act("turn on Router Discovery client"
507 " using %s via %s\n",
505 " using %s via %s",
508 naddr_ntoa(new_drp->dr_gate),
509 new_drp->dr_ifp->int_name);
510
511 rdisc_ok = 1;
512
513 } else {
514 trace_act("switch Router Discovery from"
506 naddr_ntoa(new_drp->dr_gate),
507 new_drp->dr_ifp->int_name);
508
509 rdisc_ok = 1;
510
511 } else {
512 trace_act("switch Router Discovery from"
515 " %s via %s to %s via %s\n",
513 " %s via %s to %s via %s",
516 naddr_ntoa(cur_drp->dr_gate),
517 cur_drp->dr_ifp->int_name,
518 naddr_ntoa(new_drp->dr_gate),
519 new_drp->dr_ifp->int_name);
520 }
521
522 if (rt != 0) {
523 rtchange(rt, rt->rt_state | RS_RDISC,
524 new_drp->dr_gate, new_drp->dr_gate,
525 0,0, new_drp->dr_ifp,
526 now.tv_sec, 0);
527 } else {
528 rtadd(RIP_DEFAULT, 0,
529 new_drp->dr_gate, new_drp->dr_gate,
514 naddr_ntoa(cur_drp->dr_gate),
515 cur_drp->dr_ifp->int_name,
516 naddr_ntoa(new_drp->dr_gate),
517 new_drp->dr_ifp->int_name);
518 }
519
520 if (rt != 0) {
521 rtchange(rt, rt->rt_state | RS_RDISC,
522 new_drp->dr_gate, new_drp->dr_gate,
523 0,0, new_drp->dr_ifp,
524 now.tv_sec, 0);
525 } else {
526 rtadd(RIP_DEFAULT, 0,
527 new_drp->dr_gate, new_drp->dr_gate,
530 0, 0, RS_RDISC, new_drp->dr_ifp);
528 HOPCNT_INFINITY-1, 0,
529 RS_RDISC, new_drp->dr_ifp);
531 }
532
533 /* Now turn off RIP and delete RIP routes,
534 * which might otherwise include the default
535 * we just modified.
536 */
537 rip_off();
538 }

--- 7 unchanged lines hidden (view full) ---

546 */
547static void
548parse_ad(naddr from,
549 naddr gate,
550 n_long pref,
551 u_short life,
552 struct interface *ifp)
553{
530 }
531
532 /* Now turn off RIP and delete RIP routes,
533 * which might otherwise include the default
534 * we just modified.
535 */
536 rip_off();
537 }

--- 7 unchanged lines hidden (view full) ---

545 */
546static void
547parse_ad(naddr from,
548 naddr gate,
549 n_long pref,
550 u_short life,
551 struct interface *ifp)
552{
554 static naddr bad_gate;
553 static struct msg_limit bad_gate;
555 struct dr *drp, *new_drp;
556
557
558 if (gate == RIP_DEFAULT
559 || !check_dst(gate)) {
554 struct dr *drp, *new_drp;
555
556
557 if (gate == RIP_DEFAULT
558 || !check_dst(gate)) {
560 if (bad_gate != from) {
561 msglog("router %s advertising bad gateway %s",
562 naddr_ntoa(from),
563 naddr_ntoa(gate));
564 bad_gate = from;
565 }
559 msglim(&bad_gate, from,"router %s advertising bad gateway %s",
560 naddr_ntoa(from),
561 naddr_ntoa(gate));
566 return;
567 }
568
569 /* ignore pointers to ourself and routes via unreachable networks
570 */
571 if (ifwithaddr(gate, 1, 0) != 0) {
562 return;
563 }
564
565 /* ignore pointers to ourself and routes via unreachable networks
566 */
567 if (ifwithaddr(gate, 1, 0) != 0) {
572 trace_pkt("\tdiscard Router Discovery Ad pointing at us\n");
568 trace_pkt(" discard Router Discovery Ad pointing at us");
573 return;
574 }
575 if (!on_net(gate, ifp->int_net, ifp->int_mask)) {
569 return;
570 }
571 if (!on_net(gate, ifp->int_net, ifp->int_mask)) {
576 trace_pkt("\tdiscard Router Discovery Ad"
577 " toward unreachable net\n");
572 trace_pkt(" discard Router Discovery Ad"
573 " toward unreachable net");
578 return;
579 }
580
581 /* Convert preference to an unsigned value
582 * and later bias it by the metric of the interface.
583 */
584 pref = ntohl(pref) ^ MIN_PreferenceLevel;
585

--- 119 unchanged lines hidden (view full) ---

705 sin.sin_addr.s_addr = ifp->int_brdaddr;
706 }
707 break;
708
709 case 2: /* multicast */
710 msg = "Send multicast";
711 if (ifp->int_state & IS_DUP) {
712 trace_act("abort multicast output via %s"
574 return;
575 }
576
577 /* Convert preference to an unsigned value
578 * and later bias it by the metric of the interface.
579 */
580 pref = ntohl(pref) ^ MIN_PreferenceLevel;
581

--- 119 unchanged lines hidden (view full) ---

701 sin.sin_addr.s_addr = ifp->int_brdaddr;
702 }
703 break;
704
705 case 2: /* multicast */
706 msg = "Send multicast";
707 if (ifp->int_state & IS_DUP) {
708 trace_act("abort multicast output via %s"
713 " with duplicate address\n",
709 " with duplicate address",
714 ifp->int_name);
715 return;
716 }
717 if (rdisc_sock_mcast != ifp) {
718 /* select the right interface. */
719#ifdef MCAST_PPP_BUG
720 /* Do not specifiy the primary interface explicitly
721 * if we have the multicast point-to-point kernel

--- 73 unchanged lines hidden (view full) ---

795
796/* Advertise for Router Discovery
797 */
798void
799rdisc_adv(void)
800{
801 struct interface *ifp;
802
710 ifp->int_name);
711 return;
712 }
713 if (rdisc_sock_mcast != ifp) {
714 /* select the right interface. */
715#ifdef MCAST_PPP_BUG
716 /* Do not specifiy the primary interface explicitly
717 * if we have the multicast point-to-point kernel

--- 73 unchanged lines hidden (view full) ---

791
792/* Advertise for Router Discovery
793 */
794void
795rdisc_adv(void)
796{
797 struct interface *ifp;
798
799 if (!supplier)
800 return;
803
804 rdisc_timer.tv_sec = now.tv_sec + NEVER;
805
806 for (ifp = ifnet; ifp; ifp = ifp->int_next) {
801
802 rdisc_timer.tv_sec = now.tv_sec + NEVER;
803
804 for (ifp = ifnet; ifp; ifp = ifp->int_next) {
807 if (0 != (ifp->int_state & (IS_NO_ADV_OUT
808 | IS_PASSIVE
809 | IS_ALIAS
810 | IS_BROKE)))
805 if (0 != (ifp->int_state & (IS_NO_ADV_OUT | IS_BROKE)))
811 continue;
812
813 if (!timercmp(&ifp->int_rdisc_timer, &now, >)
814 || stopint) {
815 send_adv(ifp, htonl(INADDR_ALLHOSTS_GROUP),
816 (ifp->int_state&IS_BCAST_RDISC) ? 1 : 2);
817 ifp->int_rdisc_cnt++;
818

--- 19 unchanged lines hidden (view full) ---

838 */
839void
840rdisc_sol(void)
841{
842 struct interface *ifp;
843 union ad_u u;
844
845
806 continue;
807
808 if (!timercmp(&ifp->int_rdisc_timer, &now, >)
809 || stopint) {
810 send_adv(ifp, htonl(INADDR_ALLHOSTS_GROUP),
811 (ifp->int_state&IS_BCAST_RDISC) ? 1 : 2);
812 ifp->int_rdisc_cnt++;
813

--- 19 unchanged lines hidden (view full) ---

833 */
834void
835rdisc_sol(void)
836{
837 struct interface *ifp;
838 union ad_u u;
839
840
841 if (supplier)
842 return;
843
846 rdisc_timer.tv_sec = now.tv_sec + NEVER;
847
848 for (ifp = ifnet; ifp; ifp = ifp->int_next) {
844 rdisc_timer.tv_sec = now.tv_sec + NEVER;
845
846 for (ifp = ifnet; ifp; ifp = ifp->int_next) {
849 if (0 != (ifp->int_state & (IS_NO_SOL_OUT
850 | IS_PASSIVE
851 | IS_ALIAS
852 | IS_BROKE))
847 if (0 != (ifp->int_state & (IS_NO_SOL_OUT | IS_BROKE))
853 || ifp->int_rdisc_cnt >= MAX_SOLICITATIONS)
854 continue;
855
856 if (!timercmp(&ifp->int_rdisc_timer, &now, >)) {
857 bzero(&u,sizeof(u.so));
858 u.so.icmp_type = ICMP_ROUTERSOLICIT;
859 u.so.icmp_cksum = in_cksum((u_short*)&u.so,
860 sizeof(u.so));

--- 14 unchanged lines hidden (view full) ---

875 }
876}
877
878
879/* check the IP header of a possible Router Discovery ICMP packet */
880static struct interface * /* 0 if bad */
881ck_icmp(char *act,
882 naddr from,
848 || ifp->int_rdisc_cnt >= MAX_SOLICITATIONS)
849 continue;
850
851 if (!timercmp(&ifp->int_rdisc_timer, &now, >)) {
852 bzero(&u,sizeof(u.so));
853 u.so.icmp_type = ICMP_ROUTERSOLICIT;
854 u.so.icmp_cksum = in_cksum((u_short*)&u.so,
855 sizeof(u.so));

--- 14 unchanged lines hidden (view full) ---

870 }
871}
872
873
874/* check the IP header of a possible Router Discovery ICMP packet */
875static struct interface * /* 0 if bad */
876ck_icmp(char *act,
877 naddr from,
878 struct interface *ifp,
883 naddr to,
884 union ad_u *p,
885 u_int len)
886{
879 naddr to,
880 union ad_u *p,
881 u_int len)
882{
887 struct interface *ifp;
888 char *type;
889
890
883 char *type;
884
885
891 /* If we could tell the interface on which a packet from address 0
892 * arrived, we could deal with such solicitations.
893 */
894
895 ifp = ((from == 0) ? 0 : iflookup(from));
896
897 if (p->icmp.icmp_type == ICMP_ROUTERADVERT) {
898 type = "advertisement";
899 } else if (p->icmp.icmp_type == ICMP_ROUTERSOLICIT) {
900 type = "solicitation";
901 } else {
902 return 0;
903 }
904
905 if (p->icmp.icmp_code != 0) {
886 if (p->icmp.icmp_type == ICMP_ROUTERADVERT) {
887 type = "advertisement";
888 } else if (p->icmp.icmp_type == ICMP_ROUTERSOLICIT) {
889 type = "solicitation";
890 } else {
891 return 0;
892 }
893
894 if (p->icmp.icmp_code != 0) {
906 trace_pkt("unrecognized ICMP Router"
907 " %s code=%d from %s to %s\n",
895 trace_pkt("unrecognized ICMP Router %s code=%d from %s to %s",
908 type, p->icmp.icmp_code,
909 naddr_ntoa(from), naddr_ntoa(to));
910 return 0;
911 }
912
913 trace_rdisc(act, from, to, ifp, p, len);
914
915 if (ifp == 0)

--- 5 unchanged lines hidden (view full) ---

921}
922
923
924/* read packets from the router discovery socket
925 */
926void
927read_d(void)
928{
896 type, p->icmp.icmp_code,
897 naddr_ntoa(from), naddr_ntoa(to));
898 return 0;
899 }
900
901 trace_rdisc(act, from, to, ifp, p, len);
902
903 if (ifp == 0)

--- 5 unchanged lines hidden (view full) ---

909}
910
911
912/* read packets from the router discovery socket
913 */
914void
915read_d(void)
916{
929 static naddr bad_asize, bad_len;
917 static struct msg_limit bad_asize, bad_len;
930 struct sockaddr_in from;
931 int n, fromlen, cc, hlen;
918 struct sockaddr_in from;
919 int n, fromlen, cc, hlen;
932 union {
933 struct ip ip;
934 u_short s[512/2];
935 u_char b[512];
936 } pkt;
920 struct {
921#undef USE_PASSIFNAME /* it is too bad it does not work on raw sockets */
922#ifdef USE_PASSIFNAME
923 char ifname[IFNAMSIZ];
924#endif
925 union {
926 struct ip ip;
927 u_short s[512/2];
928 u_char b[512];
929 } pkt;
930 } buf;
937 union ad_u *p;
938 n_long *wp;
939 struct interface *ifp;
940
941
942 for (;;) {
943 fromlen = sizeof(from);
931 union ad_u *p;
932 n_long *wp;
933 struct interface *ifp;
934
935
936 for (;;) {
937 fromlen = sizeof(from);
944 cc = recvfrom(rdisc_sock, &pkt, sizeof(pkt), 0,
938 cc = recvfrom(rdisc_sock, &buf, sizeof(buf), 0,
945 (struct sockaddr*)&from,
946 &fromlen);
947 if (cc <= 0) {
948 if (cc < 0 && errno != EWOULDBLOCK)
949 LOGERR("recvfrom(rdisc_sock)");
950 break;
951 }
952 if (fromlen != sizeof(struct sockaddr_in))
953 logbad(1,"impossible recvfrom(rdisc_sock) fromlen=%d",
954 fromlen);
939 (struct sockaddr*)&from,
940 &fromlen);
941 if (cc <= 0) {
942 if (cc < 0 && errno != EWOULDBLOCK)
943 LOGERR("recvfrom(rdisc_sock)");
944 break;
945 }
946 if (fromlen != sizeof(struct sockaddr_in))
947 logbad(1,"impossible recvfrom(rdisc_sock) fromlen=%d",
948 fromlen);
949#ifdef USE_PASSIFNAME
950 if ((cc -= sizeof(buf.ifname)) < 0)
951 logbad(0,"missing USE_PASSIFNAME; only %d bytes",
952 cc+sizeof(buf.ifname));
953#endif
955
954
956 hlen = pkt.ip.ip_hl << 2;
955 hlen = buf.pkt.ip.ip_hl << 2;
957 if (cc < hlen + ICMP_MINLEN)
958 continue;
956 if (cc < hlen + ICMP_MINLEN)
957 continue;
959 p = (union ad_u *)&pkt.b[hlen];
958 p = (union ad_u *)&buf.pkt.b[hlen];
960 cc -= hlen;
961
959 cc -= hlen;
960
961#ifdef USE_PASSIFNAME
962 ifp = ifwithname(buf.ifname, 0);
963 if (ifp == 0) {
964 /* maybe it is a new interface */
965 ifinit();
966 ifp = ifwithname(buf.ifname, 0);
967 if (ifp == 0) {
968 msglim(&bad_name, from.sin_addr.s_addr,
969 "impossible rdisc if_ name %.*s",
970 IFNAMSIZ, buf.ifname);
971 }
972 }
973#else
974 /* If we could tell the interface on which a packet from
975 * address 0 arrived, we could deal with such solicitations.
976 */
977 ifp = ((from.sin_addr.s_addr == 0)
978 ? 0 : iflookup(from.sin_addr.s_addr));
979#endif
962 ifp = ck_icmp("Recv",
980 ifp = ck_icmp("Recv",
963 from.sin_addr.s_addr, pkt.ip.ip_dst.s_addr,
981 from.sin_addr.s_addr, ifp,
982 buf.pkt.ip.ip_dst.s_addr,
964 p, cc);
965 if (ifp == 0)
966 continue;
967 if (ifwithaddr(from.sin_addr.s_addr, 0, 0)) {
983 p, cc);
984 if (ifp == 0)
985 continue;
986 if (ifwithaddr(from.sin_addr.s_addr, 0, 0)) {
968 trace_pkt("\tdiscard our own Router Discovery msg\n");
987 trace_pkt(" discard our own Router Discovery"
988 " message");
969 continue;
970 }
971
972 switch (p->icmp.icmp_type) {
973 case ICMP_ROUTERADVERT:
974 if (p->ad.icmp_ad_asize*4
975 < sizeof(p->ad.icmp_ad_info[0])) {
989 continue;
990 }
991
992 switch (p->icmp.icmp_type) {
993 case ICMP_ROUTERADVERT:
994 if (p->ad.icmp_ad_asize*4
995 < sizeof(p->ad.icmp_ad_info[0])) {
976 if (bad_asize != from.sin_addr.s_addr) {
977 msglog("intolerable rdisc address"
978 " size=%d",
979 p->ad.icmp_ad_asize);
980 bad_asize = from.sin_addr.s_addr;
981 }
996 msglim(&bad_asize, from.sin_addr.s_addr,
997 "intolerable rdisc address size=%d",
998 p->ad.icmp_ad_asize);
982 continue;
983 }
984 if (p->ad.icmp_ad_num == 0) {
999 continue;
1000 }
1001 if (p->ad.icmp_ad_num == 0) {
985 trace_pkt("\tempty?\n");
1002 trace_pkt(" empty?");
986 continue;
987 }
988 if (cc != (sizeof(p->ad) - sizeof(p->ad.icmp_ad_info)
989 + (p->ad.icmp_ad_num
990 * sizeof(p->ad.icmp_ad_info[0])))) {
1003 continue;
1004 }
1005 if (cc != (sizeof(p->ad) - sizeof(p->ad.icmp_ad_info)
1006 + (p->ad.icmp_ad_num
1007 * sizeof(p->ad.icmp_ad_info[0])))) {
991 if (bad_len != from.sin_addr.s_addr) {
992 msglog("rdisc length %d does not"
993 " match ad_num %d",
994 cc, p->ad.icmp_ad_num);
995 bad_len = from.sin_addr.s_addr;
996 }
1008 msglim(&bad_len, from.sin_addr.s_addr,
1009 "rdisc length %d does not match ad_num"
1010 " %d", cc, p->ad.icmp_ad_num);
997 continue;
998 }
999 if (supplier)
1000 continue;
1001 if (ifp->int_state & IS_NO_ADV_IN)
1002 continue;
1003
1004 wp = &p->ad.icmp_ad_info[0].icmp_ad_addr;

--- 28 unchanged lines hidden ---
1011 continue;
1012 }
1013 if (supplier)
1014 continue;
1015 if (ifp->int_state & IS_NO_ADV_IN)
1016 continue;
1017
1018 wp = &p->ad.icmp_ad_info[0].icmp_ad_addr;

--- 28 unchanged lines hidden ---