2 * The mrouted program is covered by the license in the accompanying file
3 * named "LICENSE". Use of the mrouted program represents acceptance of
4 * the terms and conditions listed in that file.
6 * The mrouted program is COPYRIGHT 1989 by The Board of Trustees of
7 * Leland Stanford Junior University.
10 * vif.c,v 3.8.4.56.2.1 1999/01/20 05:18:50 fenner Exp
12 * $FreeBSD: src/usr.sbin/mrouted/vif.c,v 1.15 1999/08/28 01:17:09 peter Exp $
13 * $DragonFly: src/usr.sbin/mrouted/vif.c,v 1.4 2004/03/15 18:10:28 dillon Exp $
22 struct uvif uvifs
[MAXVIFS
]; /* array of virtual interfaces */
23 vifi_t numvifs
; /* number of vifs in use */
24 int vifs_down
; /* 1=>some interfaces are down */
25 int phys_vif
; /* An enabled vif */
26 int udp_socket
; /* Since the honkin' kernel doesn't support */
27 /* ioctls on raw IP sockets, we need a UDP */
28 /* socket as well as our IGMP (raw) socket. */
30 int vifs_with_neighbors
; /* == 1 if I am a leaf */
35 struct listaddr
*nbrs
[MAXNBRS
]; /* array of neighbors */
44 * Forward declarations.
46 static void start_vif(vifi_t vifi
);
47 static void start_vif2(vifi_t vifi
);
48 static void stop_vif(vifi_t vifi
);
49 static void age_old_hosts(void);
50 static void send_probe_on_vif(struct uvif
*v
);
51 static void send_query(struct uvif
*v
);
52 static int info_version(char *p
, int plen
);
53 static void DelVif(void *arg
);
54 static int SetTimer(vifi_t vifi
, struct listaddr
*g
);
55 static int DeleteTimer(int id
);
56 static void SendQuery(void *arg
);
57 static int SetQueryTimer(struct listaddr
*g
, vifi_t vifi
, int to_expire
,
62 * Initialize the virtual interfaces, but do not install
63 * them in the kernel. Start routing on all vifs that are
64 * not down or disabled.
71 int enabled_vifs
, enabled_phyints
;
72 extern char *configfilename
;
75 vifs_with_neighbors
= 0;
79 * Configure the vifs based on the interface configuration of the
80 * the kernel and the contents of the configuration file.
81 * (Open a UDP socket for ioctl use in the config procedures if
82 * the kernel can't handle IOCTL's on the IGMP socket.)
84 #ifdef IOCTL_OK_ON_RAW_SOCKET
85 udp_socket
= igmp_socket
;
87 if ((udp_socket
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0)
88 dolog(LOG_ERR
, errno
, "UDP socket");
90 dolog(LOG_INFO
,0,"Getting vifs from kernel interfaces");
91 config_vifs_from_kernel();
92 dolog(LOG_INFO
,0,"Getting vifs from %s",configfilename
);
93 config_vifs_from_file();
96 * Quit if there are fewer than two enabled vifs.
101 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
102 if (!(v
->uv_flags
& VIFF_DISABLED
)) {
104 if (!(v
->uv_flags
& VIFF_TUNNEL
)) {
111 if (enabled_vifs
< 2)
112 dolog(LOG_ERR
, 0, "can't forward: %s",
113 enabled_vifs
== 0 ? "no enabled vifs" : "only one enabled vif");
115 if (enabled_phyints
== 0)
116 dolog(LOG_WARNING
, 0,
117 "no enabled interfaces, forwarding via tunnels only");
119 dolog(LOG_INFO
, 0, "Installing vifs in mrouted...");
120 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
121 if (!(v
->uv_flags
& VIFF_DISABLED
)) {
122 if (!(v
->uv_flags
& VIFF_DOWN
)) {
123 if (v
->uv_flags
& VIFF_TUNNEL
)
124 dolog(LOG_INFO
, 0, "vif #%d, tunnel %s -> %s", vifi
,
125 inet_fmt(v
->uv_lcl_addr
, s1
),
126 inet_fmt(v
->uv_rmt_addr
, s2
));
128 dolog(LOG_INFO
, 0, "vif #%d, phyint %s", vifi
,
129 inet_fmt(v
->uv_lcl_addr
, s1
));
131 } else dolog(LOG_INFO
, 0,
132 "%s is not yet up; vif #%u not in service",
139 * Initialize the passed vif with all appropriate default values.
140 * "t" is true if a tunnel, or false if a phyint.
143 zero_vif(struct uvif
*v
, int t
)
147 v
->uv_metric
= DEFAULT_METRIC
;
149 v
->uv_threshold
= DEFAULT_THRESHOLD
;
150 v
->uv_rate_limit
= t
? DEFAULT_TUN_RATE_LIMIT
: DEFAULT_PHY_RATE_LIMIT
;
153 v
->uv_dst_addr
= t
? 0 : dvmrp_group
;
155 v
->uv_subnetmask
= 0;
156 v
->uv_subnetbcast
= 0;
157 v
->uv_name
[0] = '\0';
159 v
->uv_neighbors
= NULL
;
160 NBRM_CLRALL(v
->uv_nbrmap
);
161 v
->uv_querier
= NULL
;
162 v
->uv_igmpv1_warn
= 0;
163 v
->uv_prune_lifetime
= 0;
164 v
->uv_leaf_timer
= 0;
168 v
->uv_blasterbuf
= NULL
;
169 v
->uv_blastercur
= NULL
;
170 v
->uv_blasterend
= NULL
;
171 v
->uv_blasterlen
= 0;
172 v
->uv_blastertimer
= 0;
179 * Start routing on all virtual interfaces that are not down or
180 * administratively disabled.
183 init_installvifs(void)
188 dolog(LOG_INFO
, 0, "Installing vifs in kernel...");
189 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
190 if (!(v
->uv_flags
& VIFF_DISABLED
)) {
191 if (!(v
->uv_flags
& VIFF_DOWN
)) {
192 if (v
->uv_flags
& VIFF_TUNNEL
)
193 dolog(LOG_INFO
, 0, "vif #%d, tunnel %s -> %s", vifi
,
194 inet_fmt(v
->uv_lcl_addr
, s1
),
195 inet_fmt(v
->uv_rmt_addr
, s2
));
197 dolog(LOG_INFO
, 0, "vif #%d, phyint %s", vifi
,
198 inet_fmt(v
->uv_lcl_addr
, s1
));
199 k_add_vif(vifi
, &uvifs
[vifi
]);
200 } else dolog(LOG_INFO
, 0,
201 "%s is not yet up; vif #%u not in service",
208 * See if any interfaces have changed from up state to down, or vice versa,
209 * including any non-multicast-capable interfaces that are in use as local
210 * tunnel end-points. Ignore interfaces that have been administratively
214 check_vif_state(void)
219 static int checking_vifs
= 0;
222 * If we get an error while checking, (e.g. two interfaces go down
223 * at once, and we decide to send a prune out one of the failed ones)
224 * then don't go into an infinite loop!
231 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
233 if (v
->uv_flags
& VIFF_DISABLED
) continue;
235 strncpy(ifr
.ifr_name
, v
->uv_name
, IFNAMSIZ
);
236 if (ioctl(udp_socket
, SIOCGIFFLAGS
, (char *)&ifr
) < 0)
237 dolog(LOG_ERR
, errno
,
238 "ioctl SIOCGIFFLAGS for %s", ifr
.ifr_name
);
240 if (v
->uv_flags
& VIFF_DOWN
) {
241 if (ifr
.ifr_flags
& IFF_UP
) {
243 "%s has come up; vif #%u now in service",
245 v
->uv_flags
&= ~VIFF_DOWN
;
248 else vifs_down
= TRUE
;
251 if (!(ifr
.ifr_flags
& IFF_UP
)) {
253 "%s has gone down; vif #%u taken out of service",
256 v
->uv_flags
|= VIFF_DOWN
;
265 * Send a DVMRP message on the specified vif. If DVMRP messages are
266 * to be encapsulated and sent "inside" the tunnel, use the special
267 * encapsulator. If it's not a tunnel or DVMRP messages are to be
268 * sent "beside" the tunnel, as required by earlier versions of mrouted,
269 * then just send the message.
272 send_on_vif(struct uvif
*v
, u_int32 dst
, int code
, int datalen
)
274 u_int32 group
= htonl(MROUTED_LEVEL
|
275 ((v
->uv_flags
& VIFF_LEAF
) ? 0 : LEAF_FLAGS
));
278 * The UNIX kernel will not decapsulate unicasts.
279 * Therefore, we don't send encapsulated unicasts.
281 if ((v
->uv_flags
& (VIFF_TUNNEL
|VIFF_OTUNNEL
)) == VIFF_TUNNEL
&&
282 ((dst
== 0) || IN_MULTICAST(ntohl(dst
))))
283 send_ipip(v
->uv_lcl_addr
, dst
? dst
: dvmrp_group
, IGMP_DVMRP
,
284 code
, group
, datalen
, v
);
286 send_igmp(v
->uv_lcl_addr
, dst
? dst
: v
->uv_dst_addr
, IGMP_DVMRP
,
287 code
, group
, datalen
);
292 * Send a probe message on vif v
295 send_probe_on_vif(struct uvif
*v
)
299 struct listaddr
*nbr
;
302 if ((v
->uv_flags
& VIFF_PASSIVE
&& v
->uv_neighbors
== NULL
) ||
303 (v
->uv_flags
& VIFF_FORCE_LEAF
))
306 p
= send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
;
308 for (i
= 0; i
< 4; i
++)
309 *p
++ = ((char *)&(dvmrp_genid
))[i
];
313 * add the neighbor list on the interface to the message
315 nbr
= v
->uv_neighbors
;
318 for (i
= 0; i
< 4; i
++)
319 *p
++ = ((char *)&nbr
->al_addr
)[i
];
324 send_on_vif(v
, 0, DVMRP_PROBE
, datalen
);
328 send_query(struct uvif
*v
)
331 dolog(LOG_DEBUG
, 0, "sending %squery on vif %d",
332 (v
->uv_flags
& VIFF_IGMPV1
) ? "v1 " : "",
334 send_igmp(v
->uv_lcl_addr
, allhosts_group
,
335 IGMP_MEMBERSHIP_QUERY
,
336 (v
->uv_flags
& VIFF_IGMPV1
) ? 0 :
337 IGMP_MAX_HOST_REPORT_DELAY
* IGMP_TIMER_SCALE
, 0, 0);
341 * Add a vifi to the kernel and start routing on it.
344 start_vif(vifi_t vifi
)
347 * Install the interface in the kernel's vif structure.
349 k_add_vif(vifi
, &uvifs
[vifi
]);
355 * Add a vifi to all the user-level data structures but don't add
356 * it to the kernel yet.
359 start_vif2(vifi_t vifi
)
366 src
= v
->uv_lcl_addr
;
369 * Update the existing route entries to take into account the new vif.
371 add_vif_to_routes(vifi
);
373 if (!(v
->uv_flags
& VIFF_TUNNEL
)) {
375 * Join the DVMRP multicast group on the interface.
376 * (This is not strictly necessary, since the kernel promiscuously
377 * receives IGMP packets addressed to ANY IP multicast group while
378 * multicast routing is enabled. However, joining the group allows
379 * this host to receive non-IGMP packets as well, such as 'pings'.)
381 k_join(dvmrp_group
, src
);
384 * Join the ALL-ROUTERS multicast group on the interface.
385 * This allows mtrace requests to loop back if they are run
386 * on the multicast router.
388 k_join(allrtrs_group
, src
);
391 * Install an entry in the routing table for the subnet to which
392 * the interface is connected.
394 start_route_updates();
395 update_route(v
->uv_subnet
, v
->uv_subnetmask
, 0, 0, vifi
, NULL
);
396 for (p
= v
->uv_addrs
; p
; p
= p
->pa_next
) {
397 start_route_updates();
398 update_route(p
->pa_subnet
, p
->pa_subnetmask
, 0, 0, vifi
, NULL
);
402 * Until neighbors are discovered, assume responsibility for sending
403 * periodic group membership queries to the subnet. Send the first
406 v
->uv_flags
|= VIFF_QUERIER
;
408 dolog(LOG_DEBUG
, 0, "assuming querier duties on vif %d", vifi
);
412 v
->uv_leaf_timer
= LEAF_CONFIRMATION_TIME
;
415 * Send a probe via the new vif to look for neighbors.
417 send_probe_on_vif(v
);
421 * Stop routing on the specified virtual interface.
424 stop_vif(vifi_t vifi
)
432 if (!(v
->uv_flags
& VIFF_TUNNEL
)) {
434 * Depart from the DVMRP multicast group on the interface.
436 k_leave(dvmrp_group
, v
->uv_lcl_addr
);
439 * Depart from the ALL-ROUTERS multicast group on the interface.
441 k_leave(allrtrs_group
, v
->uv_lcl_addr
);
444 * Update the entry in the routing table for the subnet to which
445 * the interface is connected, to take into account the interface
448 start_route_updates();
449 update_route(v
->uv_subnet
, v
->uv_subnetmask
, UNREACHABLE
, 0, vifi
, NULL
);
450 for (p
= v
->uv_addrs
; p
; p
= p
->pa_next
) {
451 start_route_updates();
452 update_route(p
->pa_subnet
, p
->pa_subnetmask
, UNREACHABLE
, 0, vifi
, NULL
);
456 * Discard all group addresses. (No need to tell kernel;
457 * the k_del_vif() call, below, will clean up kernel state.)
459 while (v
->uv_groups
!= NULL
) {
461 v
->uv_groups
= a
->al_next
;
466 dolog(LOG_DEBUG
, 0, "releasing querier duties on vif %d", vifi
);
467 v
->uv_flags
&= ~VIFF_QUERIER
;
471 * Update the existing route entries to take into account the vif failure.
473 delete_vif_from_routes(vifi
);
476 * Delete the interface from the kernel's vif structure.
481 * Discard all neighbor addresses.
483 if (!NBRM_ISEMPTY(v
->uv_nbrmap
))
484 vifs_with_neighbors
--;
486 while (v
->uv_neighbors
!= NULL
) {
488 v
->uv_neighbors
= a
->al_next
;
489 nbrs
[a
->al_index
] = NULL
;
492 NBRM_CLRALL(v
->uv_nbrmap
);
497 * stop routing on all vifs
507 for (vifi
= 0; vifi
< numvifs
; vifi
++) {
509 while (v
->uv_groups
!= NULL
) {
511 v
->uv_groups
= a
->al_next
;
514 while (v
->uv_neighbors
!= NULL
) {
516 v
->uv_neighbors
= a
->al_next
;
517 nbrs
[a
->al_index
] = NULL
;
520 while (v
->uv_acl
!= NULL
) {
522 v
->uv_acl
= acl
->acl_next
;
530 * Find the virtual interface from which an incoming packet arrived,
531 * based on the packet's source and destination IP addresses.
534 find_vif(u_int32 src
, u_int32 dst
)
540 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
541 if (!(v
->uv_flags
& (VIFF_DOWN
|VIFF_DISABLED
))) {
542 if (v
->uv_flags
& VIFF_TUNNEL
) {
543 if (src
== v
->uv_rmt_addr
&& (dst
== v
->uv_lcl_addr
||
548 if ((src
& v
->uv_subnetmask
) == v
->uv_subnet
&&
549 ((v
->uv_subnetmask
== 0xffffffff) ||
550 (src
!= v
->uv_subnetbcast
)))
552 for (p
=v
->uv_addrs
; p
; p
=p
->pa_next
) {
553 if ((src
& p
->pa_subnetmask
) == p
->pa_subnet
&&
554 ((p
->pa_subnetmask
== 0xffffffff) ||
555 (src
!= p
->pa_subnetbcast
)))
572 * Decrement the old-hosts-present timer for each
573 * active group on each vif.
575 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++)
576 for (g
= v
->uv_groups
; g
!= NULL
; g
= g
->al_next
)
583 * Send group membership queries on each interface for which I am querier.
584 * Note that technically, there should be a timer per interface, as the
585 * dynamics of querier election can cause the "right" time to send a
586 * query to be different on different interfaces. However, this simple
587 * implementation only ever sends queries sooner than the "right" time,
588 * so can not cause loss of membership (but can send more packets than
597 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
598 if (v
->uv_flags
& VIFF_QUERIER
) {
606 * Process an incoming host membership query. Warn about
607 * IGMP version mismatches, perform querier election, and
608 * handle group-specific queries when we're not the querier.
611 accept_membership_query(u_int32 src
, u_int32 dst
, u_int32 group
, int tmo
)
616 if ((vifi
= find_vif(src
, dst
)) == NO_VIF
||
617 (uvifs
[vifi
].uv_flags
& VIFF_TUNNEL
)) {
619 "ignoring group membership query from non-adjacent host %s",
626 if ((tmo
== 0 && !(v
->uv_flags
& VIFF_IGMPV1
)) ||
627 (tmo
!= 0 && (v
->uv_flags
& VIFF_IGMPV1
))) {
631 * Exponentially back-off warning rate
633 i
= ++v
->uv_igmpv1_warn
;
634 while (i
&& !(i
& 1))
637 dolog(LOG_WARNING
, 0, "%s %s on vif %d, %s",
638 tmo
== 0 ? "Received IGMPv1 report from"
639 : "Received IGMPv2 report from",
642 tmo
== 0 ? "please configure vif for IGMPv1"
643 : "but I am configured for IGMPv1");
646 if (v
->uv_querier
== NULL
|| v
->uv_querier
->al_addr
!= src
) {
649 * - A query from a new querier, with a lower source address
650 * than the current querier (who might be me)
651 * - A query from a new router that just started up and doesn't
652 * know who the querier is.
654 if (ntohl(src
) < (v
->uv_querier
? ntohl(v
->uv_querier
->al_addr
)
655 : ntohl(v
->uv_lcl_addr
))) {
657 dolog(LOG_DEBUG
, 0, "new querier %s (was %s) on vif %d",
659 v
->uv_querier
? inet_fmt(v
->uv_querier
->al_addr
, s2
) :
661 if (!v
->uv_querier
) {
662 v
->uv_querier
= (struct listaddr
*)
663 malloc(sizeof(struct listaddr
));
664 v
->uv_flags
&= ~VIFF_QUERIER
;
666 time(&v
->uv_querier
->al_ctime
);
667 v
->uv_querier
->al_addr
= src
;
670 dolog(LOG_DEBUG
, 0, "ignoring query from %s; querier on vif %d is still %s",
671 inet_fmt(src
, s1
), vifi
,
672 v
->uv_querier
? inet_fmt(v
->uv_querier
->al_addr
, s2
) :
680 * Reset the timer since we've received a query.
682 if (v
->uv_querier
&& src
== v
->uv_querier
->al_addr
)
683 v
->uv_querier
->al_timer
= 0;
686 * If this is a Group-Specific query which we did not source,
687 * we must set our membership timer to [Last Member Query Count] *
688 * the [Max Response Time] in the packet.
690 if (!(v
->uv_flags
& (VIFF_IGMPV1
|VIFF_QUERIER
)) && group
!= 0 &&
691 src
!= v
->uv_lcl_addr
) {
696 "%s for %s from %s on vif %d, timer %d",
697 "Group-specific membership query",
698 inet_fmt(group
, s2
), inet_fmt(src
, s1
), vifi
, tmo
);
700 for (g
= v
->uv_groups
; g
!= NULL
; g
= g
->al_next
) {
701 if (group
== g
->al_addr
&& g
->al_query
== 0) {
702 /* setup a timeout to remove the group membership */
704 g
->al_timerid
= DeleteTimer(g
->al_timerid
);
705 g
->al_timer
= IGMP_LAST_MEMBER_QUERY_COUNT
*
706 tmo
/ IGMP_TIMER_SCALE
;
707 /* use al_query to record our presence in last-member state */
709 g
->al_timerid
= SetTimer(vifi
, g
);
712 "timer for grp %s on vif %d set to %d",
713 inet_fmt(group
, s2
), vifi
, g
->al_timer
);
721 * Process an incoming group membership report.
724 accept_group_report(u_int32 src
, u_int32 dst
, u_int32 group
, int r_type
)
730 if ((vifi
= find_vif(src
, dst
)) == NO_VIF
||
731 (uvifs
[vifi
].uv_flags
& VIFF_TUNNEL
)) {
733 "ignoring group membership report from non-adjacent host %s",
741 * Look for the group in our group list; if found, reset its timer.
743 for (g
= v
->uv_groups
; g
!= NULL
; g
= g
->al_next
) {
744 if (group
== g
->al_addr
) {
745 if (r_type
== IGMP_V1_MEMBERSHIP_REPORT
)
746 g
->al_old
= OLD_AGE_THRESHOLD
;
748 g
->al_reporter
= src
;
750 /** delete old timers, set a timer for expiration **/
751 g
->al_timer
= IGMP_GROUP_MEMBERSHIP_INTERVAL
;
753 g
->al_query
= DeleteTimer(g
->al_query
);
755 g
->al_timerid
= DeleteTimer(g
->al_timerid
);
756 g
->al_timerid
= SetTimer(vifi
, g
);
762 * If not found, add it to the list and update kernel cache.
765 g
= (struct listaddr
*)malloc(sizeof(struct listaddr
));
767 dolog(LOG_ERR
, 0, "ran out of memory"); /* fatal */
770 if (r_type
== IGMP_V1_MEMBERSHIP_REPORT
)
771 g
->al_old
= OLD_AGE_THRESHOLD
;
775 /** set a timer for expiration **/
777 g
->al_timer
= IGMP_GROUP_MEMBERSHIP_INTERVAL
;
778 g
->al_reporter
= src
;
779 g
->al_timerid
= SetTimer(vifi
, g
);
780 g
->al_next
= v
->uv_groups
;
784 update_lclgrp(vifi
, group
);
788 * Check if a graft is necessary for this group
790 chkgrp_graft(vifi
, group
);
794 * Process an incoming IGMPv2 Leave Group message.
797 accept_leave_message(u_int32 src
, u_int32 dst
, u_int32 group
)
803 if ((vifi
= find_vif(src
, dst
)) == NO_VIF
||
804 (uvifs
[vifi
].uv_flags
& VIFF_TUNNEL
)) {
806 "ignoring group leave report from non-adjacent host %s",
813 if (!(v
->uv_flags
& VIFF_QUERIER
) || (v
->uv_flags
& VIFF_IGMPV1
))
817 * Look for the group in our group list in order to set up a short-timeout
820 for (g
= v
->uv_groups
; g
!= NULL
; g
= g
->al_next
) {
821 if (group
== g
->al_addr
) {
824 "[vif.c, _accept_leave_message] %d %d \n",
825 g
->al_old
, g
->al_query
);
827 /* Ignore the leave message if there are old hosts present */
831 /* still waiting for a reply to a query, ignore the leave */
835 /** delete old timer set a timer for expiration **/
837 g
->al_timerid
= DeleteTimer(g
->al_timerid
);
839 #if IGMP_LAST_MEMBER_QUERY_COUNT != 2
840 This code needs to be updated to keep a counter of the number
841 of queries remaining
.
843 /** send a group specific querry **/
844 g
->al_timer
= IGMP_LAST_MEMBER_QUERY_INTERVAL
*
845 (IGMP_LAST_MEMBER_QUERY_COUNT
+ 1);
846 send_igmp(v
->uv_lcl_addr
, g
->al_addr
,
847 IGMP_MEMBERSHIP_QUERY
,
848 IGMP_LAST_MEMBER_QUERY_INTERVAL
* IGMP_TIMER_SCALE
,
850 g
->al_query
= SetQueryTimer(g
, vifi
,
851 IGMP_LAST_MEMBER_QUERY_INTERVAL
,
852 IGMP_LAST_MEMBER_QUERY_INTERVAL
* IGMP_TIMER_SCALE
);
853 g
->al_timerid
= SetTimer(vifi
, g
);
861 * Send a periodic probe on all vifs.
862 * Useful to determine one-way interfaces.
863 * Detect neighbor loss faster.
866 probe_for_neighbors(void)
871 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
872 if (!(v
->uv_flags
& (VIFF_DOWN
|VIFF_DISABLED
))) {
873 send_probe_on_vif(v
);
880 * Send a list of all of our neighbors to the requestor, `src'.
883 accept_neighbor_request(u_int32 src
, u_int32 dst
)
890 u_int32 temp_addr
, them
= src
;
892 #define PUT_ADDR(a) temp_addr = ntohl(a); \
893 *p++ = temp_addr >> 24; \
894 *p++ = (temp_addr >> 16) & 0xFF; \
895 *p++ = (temp_addr >> 8) & 0xFF; \
896 *p++ = temp_addr & 0xFF;
898 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
901 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
902 if (v
->uv_flags
& VIFF_DISABLED
)
907 for (la
= v
->uv_neighbors
; la
; la
= la
->al_next
) {
909 /* Make sure that there's room for this neighbor... */
910 if (datalen
+ (ncount
== 0 ? 4 + 3 + 4 : 4) > MAX_DVMRP_DATA_LEN
) {
911 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS
,
912 htonl(MROUTED_LEVEL
), datalen
);
913 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
918 /* Put out the header for this neighbor list... */
920 PUT_ADDR(v
->uv_lcl_addr
);
922 *p
++ = v
->uv_threshold
;
928 PUT_ADDR(la
->al_addr
);
935 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS
,
936 htonl(MROUTED_LEVEL
), datalen
);
940 * Send a list of all of our neighbors to the requestor, `src'.
943 accept_neighbor_request2(u_int32 src
, u_int32 dst
)
952 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
955 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
956 u_short vflags
= v
->uv_flags
;
959 if (vflags
& VIFF_TUNNEL
)
960 rflags
|= DVMRP_NF_TUNNEL
;
961 if (vflags
& VIFF_SRCRT
)
962 rflags
|= DVMRP_NF_SRCRT
;
963 if (vflags
& VIFF_DOWN
)
964 rflags
|= DVMRP_NF_DOWN
;
965 if (vflags
& VIFF_DISABLED
)
966 rflags
|= DVMRP_NF_DISABLED
;
967 if (vflags
& VIFF_QUERIER
)
968 rflags
|= DVMRP_NF_QUERIER
;
969 if (vflags
& VIFF_LEAF
)
970 rflags
|= DVMRP_NF_LEAF
;
972 la
= v
->uv_neighbors
;
975 * include down & disabled interfaces and interfaces on
978 if (rflags
& DVMRP_NF_TUNNEL
)
979 rflags
|= DVMRP_NF_DOWN
;
980 if (datalen
> MAX_DVMRP_DATA_LEN
- 12) {
981 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS2
,
982 htonl(MROUTED_LEVEL
), datalen
);
983 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
986 *(u_int
*)p
= v
->uv_lcl_addr
;
989 *p
++ = v
->uv_threshold
;
992 *(u_int
*)p
= v
->uv_rmt_addr
;
996 for ( ; la
; la
= la
->al_next
) {
997 /* Make sure that there's room for this neighbor... */
998 if (datalen
+ (ncount
== 0 ? 4+4+4 : 4) > MAX_DVMRP_DATA_LEN
) {
999 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS2
,
1000 htonl(MROUTED_LEVEL
), datalen
);
1001 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
1005 /* Put out the header for this neighbor list... */
1007 /* If it's a one-way tunnel, mark it down. */
1008 if (rflags
& DVMRP_NF_TUNNEL
&& la
->al_flags
& NBRF_ONEWAY
)
1009 rflags
|= DVMRP_NF_DOWN
;
1010 *(u_int
*)p
= v
->uv_lcl_addr
;
1012 *p
++ = v
->uv_metric
;
1013 *p
++ = v
->uv_threshold
;
1019 /* Don't report one-way peering on phyint at all */
1020 if (!(rflags
& DVMRP_NF_TUNNEL
) && la
->al_flags
& NBRF_ONEWAY
)
1022 *(u_int
*)p
= la
->al_addr
;
1028 *(u_int
*)p
= v
->uv_rmt_addr
;
1036 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS2
,
1037 htonl(MROUTED_LEVEL
), datalen
);
1041 accept_info_request(u_int32 src
, u_int32 dst
, u_char
*p
, int datalen
)
1047 q
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
1049 /* To be general, this must deal properly with breaking up over-sized
1050 * packets. That implies passing a length to each function, and
1051 * allowing each function to request to be called again. Right now,
1052 * we're only implementing the one thing we are positive will fit into
1053 * a single packet, so we wimp out.
1055 while (datalen
> 0) {
1058 case DVMRP_INFO_VERSION
:
1059 len
= info_version(q
, RECV_BUF_SIZE
-(q
-(u_char
*)send_buf
));
1062 case DVMRP_INFO_NEIGHBORS
:
1064 dolog(LOG_INFO
, 0, "ignoring unknown info type %d", *p
);
1070 len
= (*(p
+1) + 1) * 4;
1076 send_igmp(INADDR_ANY
, src
, IGMP_DVMRP
, DVMRP_INFO_REPLY
,
1077 htonl(MROUTED_LEVEL
), outlen
);
1081 * Information response -- return version string
1084 info_version(char *p
, int plen
)
1087 extern char versionstring
[];
1089 *p
++ = DVMRP_INFO_VERSION
;
1090 p
++; /* skip over length */
1091 *p
++ = 0; /* zero out */
1092 *p
++ = 0; /* reserved fields */
1093 strncpy(p
, versionstring
, plen
- 4);
1096 len
= strlen(versionstring
);
1097 return ((len
+ 3) / 4);
1101 * Process an incoming neighbor-list message.
1104 accept_neighbors(u_int32 src
, u_int32 dst
, u_char
*p
, int datalen
,
1107 dolog(LOG_INFO
, 0, "ignoring spurious DVMRP neighbor list from %s to %s",
1108 inet_fmt(src
, s1
), inet_fmt(dst
, s2
));
1113 * Process an incoming neighbor-list message.
1116 accept_neighbors2(u_int32 src
, u_int32 dst
, u_char
*p
, int datalen
,
1120 dolog(LOG_DEBUG
, 0, "ignoring spurious DVMRP neighbor list2 from %s to %s",
1121 inet_fmt(src
, s1
), inet_fmt(dst
, s2
));
1125 * Process an incoming info reply message.
1128 accept_info_reply(u_int32 src
, u_int32 dst
, u_char
*p
, int datalen
)
1131 dolog(LOG_DEBUG
, 0, "ignoring spurious DVMRP info reply from %s to %s",
1132 inet_fmt(src
, s1
), inet_fmt(dst
, s2
));
1137 * Update the neighbor entry for neighbor 'addr' on vif 'vifi'.
1138 * 'msgtype' is the type of DVMRP message received from the neighbor.
1139 * Return the neighbor entry if 'addr' is a valid neighbor, FALSE otherwise.
1142 update_neighbor(vifi_t vifi
, u_int32 addr
, int msgtype
, char *p
, int datalen
,
1147 int pv
= level
& 0xff;
1148 int mv
= (level
>> 8) & 0xff;
1150 int in_router_list
= 0;
1153 u_int32 send_tables
= 0;
1155 int do_reset
= FALSE
;
1160 * Confirm that 'addr' is a valid neighbor address on vif 'vifi'.
1161 * IT IS ASSUMED that this was preceded by a call to find_vif(), which
1162 * checks that 'addr' is either a valid remote tunnel endpoint or a
1163 * non-broadcast address belonging to a directly-connected subnet.
1164 * Therefore, here we check only that 'addr' is not our own address
1165 * (due to an impostor or erroneous loopback) or an address of the form
1166 * {subnet,0} ("the unknown host"). These checks are not performed in
1167 * find_vif() because those types of address are acceptable for some
1168 * types of IGMP message (such as group membership reports).
1170 if (!(v
->uv_flags
& VIFF_TUNNEL
) &&
1171 (addr
== v
->uv_lcl_addr
||
1172 addr
== v
->uv_subnet
)) {
1173 dolog(LOG_WARNING
, 0,
1174 "received DVMRP message from %s: %s",
1175 (addr
== v
->uv_lcl_addr
) ? "self (check device loopback)" :
1176 "'the unknown host'",
1177 inet_fmt(addr
, s1
));
1182 * Ignore all neighbors on vifs forced into leaf mode
1184 if (v
->uv_flags
& VIFF_FORCE_LEAF
) {
1189 * mrouted's version 3.3 and later include the generation ID
1190 * and the list of neighbors on the vif in their probe messages.
1192 if (msgtype
== DVMRP_PROBE
&& ((pv
== 3 && mv
> 2) ||
1193 (pv
> 3 && pv
< 10))) {
1196 IF_DEBUG(DEBUG_PEER
)
1197 dolog(LOG_DEBUG
, 0, "checking probe from %s (%d.%d) on vif %d",
1198 inet_fmt(addr
, s1
), pv
, mv
, vifi
);
1201 dolog(LOG_WARNING
, 0,
1202 "received truncated probe message from %s (len %d)",
1203 inet_fmt(addr
, s1
), datalen
);
1209 for (i
= 0; i
< 4; i
++)
1210 ((char *)&genid
)[i
] = *p
++;
1213 while (datalen
> 0) {
1215 dolog(LOG_WARNING
, 0,
1216 "received truncated probe message from %s (len %d)",
1217 inet_fmt(addr
, s1
), datalen
);
1220 for (i
= 0; i
< 4; i
++)
1221 ((char *)&router
)[i
] = *p
++;
1224 if (router
== v
->uv_lcl_addr
) {
1231 if ((pv
== 3 && mv
== 255) || (pv
> 3 && pv
< 10))
1235 * Look for addr in list of neighbors.
1237 for (n
= v
->uv_neighbors
; n
!= NULL
; n
= n
->al_next
) {
1238 if (addr
== n
->al_addr
) {
1247 * If this neighbor follows the DVMRP spec, start the probe
1248 * handshake. If not, then it doesn't require the probe
1249 * handshake, so establish the peering immediately.
1251 if (dvmrpspec
&& (msgtype
!= DVMRP_PROBE
))
1254 for (i
= 0; i
< MAXNBRS
; i
++)
1255 if (nbrs
[i
] == NULL
)
1259 /* XXX This is a severe new restriction. */
1260 /* XXX want extensible bitmaps! */
1261 dolog(LOG_ERR
, 0, "Can't handle %dth neighbor %s on vif %d!",
1262 MAXNBRS
, inet_fmt(addr
, s1
), vifi
);
1267 * Add it to our list of neighbors.
1269 IF_DEBUG(DEBUG_PEER
)
1270 dolog(LOG_DEBUG
, 0, "New neighbor %s on vif %d v%d.%d nf 0x%02x idx %d",
1271 inet_fmt(addr
, s1
), vifi
, level
& 0xff, (level
>> 8) & 0xff,
1272 (level
>> 16) & 0xff, i
);
1274 n
= (struct listaddr
*)malloc(sizeof(struct listaddr
));
1276 dolog(LOG_ERR
, 0, "ran out of memory"); /* fatal */
1281 n
->al_genid
= has_genid
? genid
: 0;
1287 n
->al_flags
= has_genid
? NBRF_GENID
: 0;
1288 n
->al_next
= v
->uv_neighbors
;
1289 v
->uv_neighbors
= n
;
1292 * If we are not configured to peer with non-pruning routers,
1293 * check the deprecated "I-know-how-to-prune" bit. This bit
1294 * was MBZ in early mrouted implementations (<3.5) and is required
1295 * to be set by the DVMRPv3 specification.
1297 if (!(v
->uv_flags
& VIFF_ALLOW_NONPRUNERS
) &&
1298 !((level
& 0x020000) || (pv
== 3 && mv
< 5))) {
1299 n
->al_flags
|= NBRF_TOOOLD
;
1303 * If this router implements the DVMRPv3 spec, then don't peer
1304 * with him if we haven't yet established a bidirectional connection.
1307 if (!in_router_list
) {
1308 IF_DEBUG(DEBUG_PEER
)
1309 dolog(LOG_DEBUG
, 0, "waiting for probe from %s with my addr",
1310 inet_fmt(addr
, s1
));
1311 n
->al_flags
|= NBRF_WAITING
;
1316 if (n
->al_flags
& NBRF_DONTPEER
) {
1317 IF_DEBUG(DEBUG_PEER
)
1318 dolog(LOG_DEBUG
, 0, "not peering with %s on vif %d because %x",
1319 inet_fmt(addr
, s1
), vifi
, n
->al_flags
& NBRF_DONTPEER
);
1324 * If we thought that we had no neighbors on this vif, send a route
1325 * report to the vif. If this is just a new neighbor on the same
1326 * vif, send the route report just to the new neighbor.
1328 if (NBRM_ISEMPTY(v
->uv_nbrmap
)) {
1329 send_tables
= v
->uv_dst_addr
;
1330 vifs_with_neighbors
++;
1336 NBRM_SET(i
, v
->uv_nbrmap
);
1337 add_neighbor_to_routes(vifi
, i
);
1340 * Found it. Reset its timer.
1344 if (n
->al_flags
& NBRF_WAITING
&& msgtype
== DVMRP_PROBE
) {
1345 n
->al_flags
&= ~NBRF_WAITING
;
1346 if (!in_router_list
) {
1347 dolog(LOG_WARNING
, 0, "possible one-way peering with %s on vif %d",
1348 inet_fmt(addr
, s1
), vifi
);
1349 n
->al_flags
|= NBRF_ONEWAY
;
1352 if (NBRM_ISEMPTY(v
->uv_nbrmap
)) {
1353 send_tables
= v
->uv_dst_addr
;
1354 vifs_with_neighbors
++;
1358 NBRM_SET(n
->al_index
, v
->uv_nbrmap
);
1359 add_neighbor_to_routes(vifi
, n
->al_index
);
1360 IF_DEBUG(DEBUG_PEER
)
1361 dolog(LOG_DEBUG
, 0, "%s on vif %d exits WAITING",
1362 inet_fmt(addr
, s1
), vifi
);
1366 if (n
->al_flags
& NBRF_ONEWAY
&& msgtype
== DVMRP_PROBE
) {
1367 if (in_router_list
) {
1368 if (NBRM_ISEMPTY(v
->uv_nbrmap
))
1369 vifs_with_neighbors
++;
1370 NBRM_SET(n
->al_index
, v
->uv_nbrmap
);
1371 add_neighbor_to_routes(vifi
, n
->al_index
);
1372 dolog(LOG_NOTICE
, 0, "peering with %s on vif %d is no longer one-way",
1373 inet_fmt(addr
, s1
), vifi
);
1374 n
->al_flags
&= ~NBRF_ONEWAY
;
1376 /* XXX rate-limited warning message? */
1377 IF_DEBUG(DEBUG_PEER
)
1378 dolog(LOG_DEBUG
, 0, "%s on vif %d is still ONEWAY",
1379 inet_fmt(addr
, s1
), vifi
);
1384 * When peering with a genid-capable but pre-DVMRP spec peer,
1385 * we might bring up the peering with a route report and not
1386 * remember his genid. Assume that he doesn't send a route
1387 * report and then reboot before sending a probe.
1389 if (has_genid
&& !(n
->al_flags
& NBRF_GENID
)) {
1390 n
->al_flags
|= NBRF_GENID
;
1391 n
->al_genid
= genid
;
1395 * update the neighbors version and protocol number and genid
1396 * if changed => router went down and came up,
1397 * so take action immediately.
1399 if ((n
->al_pv
!= pv
) ||
1401 (has_genid
&& n
->al_genid
!= genid
)) {
1404 IF_DEBUG(DEBUG_PEER
)
1406 "version/genid change neighbor %s [old:%d.%d/%8x, new:%d.%d/%8x]",
1408 n
->al_pv
, n
->al_mv
, n
->al_genid
, pv
, mv
, genid
);
1412 n
->al_genid
= genid
;
1416 if ((pv
== 3 && mv
> 2) || (pv
> 3 && pv
< 10)) {
1417 if (!(n
->al_flags
& VIFF_ONEWAY
) && has_genid
&& !in_router_list
&&
1418 (time(NULL
) - n
->al_ctime
> 20)) {
1419 if (NBRM_ISSET(n
->al_index
, v
->uv_nbrmap
)) {
1420 NBRM_CLR(n
->al_index
, v
->uv_nbrmap
);
1421 if (NBRM_ISEMPTY(v
->uv_nbrmap
))
1422 vifs_with_neighbors
--;
1424 delete_neighbor_from_routes(addr
, vifi
, n
->al_index
);
1425 reset_neighbor_state(vifi
, addr
);
1426 dolog(LOG_WARNING
, 0, "peering with %s on vif %d is one-way",
1427 inet_fmt(addr
, s1
), vifi
);
1428 n
->al_flags
|= NBRF_ONEWAY
;
1432 if (n
->al_flags
& NBRF_DONTPEER
) {
1433 IF_DEBUG(DEBUG_PEER
)
1434 dolog(LOG_DEBUG
, 0, "not peering with %s on vif %d because %x",
1435 inet_fmt(addr
, s1
), vifi
, n
->al_flags
& NBRF_DONTPEER
);
1439 /* check "leaf" flag */
1442 reset_neighbor_state(vifi
, addr
);
1447 send_probe_on_vif(v
);
1448 report(ALL_ROUTES
, vifi
, send_tables
);
1450 v
->uv_leaf_timer
= 0;
1451 v
->uv_flags
&= ~VIFF_LEAF
;
1458 * On every timer interrupt, advance the timer in each neighbor and
1459 * group entry on every vif.
1466 struct listaddr
*a
, *prev_a
;
1469 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
1470 if (v
->uv_leaf_timer
&& (v
->uv_leaf_timer
-= TIMER_INTERVAL
== 0)) {
1471 v
->uv_flags
|= VIFF_LEAF
;
1474 for (prev_a
= (struct listaddr
*)&(v
->uv_neighbors
),
1475 a
= v
->uv_neighbors
;
1477 prev_a
= a
, a
= a
->al_next
) {
1481 if (((a
->al_pv
== 3) && (a
->al_mv
>= 3)) ||
1482 ((a
->al_pv
> 3) && (a
->al_pv
< 10)))
1483 exp_time
= NEIGHBOR_EXPIRE_TIME
;
1485 exp_time
= OLD_NEIGHBOR_EXPIRE_TIME
;
1487 if ((a
->al_timer
+= TIMER_INTERVAL
) < exp_time
)
1490 IF_DEBUG(DEBUG_PEER
)
1491 dolog(LOG_DEBUG
, 0, "Neighbor %s (%d.%d) expired after %d seconds",
1492 inet_fmt(a
->al_addr
, s1
), a
->al_pv
, a
->al_mv
, exp_time
);
1495 * Neighbor has expired; delete it from the neighbor list,
1496 * delete it from the 'dominants' and 'subordinates arrays of
1497 * any route entries.
1499 NBRM_CLR(a
->al_index
, v
->uv_nbrmap
);
1500 nbrs
[a
->al_index
] = NULL
; /* XXX is it a good idea to reuse indxs? */
1503 prev_a
->al_next
= a
->al_next
;
1505 a
= prev_a
;/*XXX use ** */
1507 delete_neighbor_from_routes(addr
, vifi
, idx
);
1508 reset_neighbor_state(vifi
, addr
);
1510 if (NBRM_ISEMPTY(v
->uv_nbrmap
))
1511 vifs_with_neighbors
--;
1513 v
->uv_leaf_timer
= LEAF_CONFIRMATION_TIME
;
1516 if (v
->uv_querier
&&
1517 (v
->uv_querier
->al_timer
+= TIMER_INTERVAL
) >
1518 IGMP_OTHER_QUERIER_PRESENT_INTERVAL
) {
1520 * The current querier has timed out. We must become the
1523 IF_DEBUG(DEBUG_IGMP
)
1524 dolog(LOG_DEBUG
, 0, "querier %s timed out",
1525 inet_fmt(v
->uv_querier
->al_addr
, s1
));
1526 free(v
->uv_querier
);
1527 v
->uv_querier
= NULL
;
1528 v
->uv_flags
|= VIFF_QUERIER
;
1535 * Returns the neighbor info struct for a given neighbor
1538 neighbor_info(vifi_t vifi
, u_int32 addr
)
1542 for (u
= uvifs
[vifi
].uv_neighbors
; u
; u
= u
->al_next
)
1543 if (u
->al_addr
== addr
)
1549 static struct vnflags
{
1553 { VIFF_DOWN
, "down" },
1554 { VIFF_DISABLED
, "disabled" },
1555 { VIFF_QUERIER
, "querier" },
1556 { VIFF_ONEWAY
, "one-way" },
1557 { VIFF_LEAF
, "leaf" },
1558 { VIFF_IGMPV1
, "IGMPv1" },
1559 { VIFF_REXMIT_PRUNES
, "rexmit_prunes" },
1560 { VIFF_PASSIVE
, "passive" },
1561 { VIFF_ALLOW_NONPRUNERS
,"allow_nonpruners" },
1562 { VIFF_NOFLOOD
, "noflood" },
1563 { VIFF_NOTRANSIT
, "notransit" },
1564 { VIFF_BLASTER
, "blaster" },
1565 { VIFF_FORCE_LEAF
, "force_leaf" },
1566 { VIFF_OTUNNEL
, "old-tunnel" },
1569 static struct vnflags nbrflags
[] = {
1570 { NBRF_LEAF
, "leaf" },
1571 { NBRF_GENID
, "have-genid" },
1572 { NBRF_WAITING
, "waiting" },
1573 { NBRF_ONEWAY
, "one-way" },
1574 { NBRF_TOOOLD
, "too old" },
1575 { NBRF_TOOMANYROUTES
, "too many routes" },
1576 { NBRF_NOTPRUNING
, "not pruning?" },
1580 * Print the contents of the uvifs array on file 'fp'.
1589 struct vif_acl
*acl
;
1591 struct sioc_vif_req v_req
;
1596 fprintf(fp
, "vifs_with_neighbors = %d\n", vifs_with_neighbors
);
1598 if (vifs_with_neighbors
== 1)
1599 fprintf(fp
,"[This host is a leaf]\n\n");
1602 "\nVirtual Interface Table\n%s",
1603 "Vif Name Local-Address ");
1605 "M Thr Rate Flags\n");
1607 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
1609 fprintf(fp
, "%2u %6s %-15s %6s: %-18s %2u %3u %5u ",
1612 inet_fmt(v
->uv_lcl_addr
, s1
),
1613 (v
->uv_flags
& VIFF_TUNNEL
) ?
1616 (v
->uv_flags
& VIFF_TUNNEL
) ?
1617 inet_fmt(v
->uv_rmt_addr
, s2
) :
1618 inet_fmts(v
->uv_subnet
, v
->uv_subnetmask
, s3
),
1623 for (i
= 0; i
< sizeof(vifflags
) / sizeof(struct vnflags
); i
++)
1624 if (v
->uv_flags
& vifflags
[i
].vn_flag
)
1625 fprintf(fp
, " %s", vifflags
[i
].vn_name
);
1629 fprintf(fp, " #routes: %d\n", v->uv_nroutes);
1631 if (v
->uv_admetric
!= 0)
1632 fprintf(fp
, " advert-metric %2u\n",
1635 label
= "alternate subnets:";
1636 for (p
= v
->uv_addrs
; p
; p
= p
->pa_next
) {
1637 fprintf(fp
, " %18s %s\n", label
,
1638 inet_fmts(p
->pa_subnet
, p
->pa_subnetmask
, s1
));
1643 for (a
= v
->uv_neighbors
; a
!= NULL
; a
= a
->al_next
) {
1644 fprintf(fp
, " %6s %s (%d.%d) [%d]",
1645 label
, inet_fmt(a
->al_addr
, s1
), a
->al_pv
, a
->al_mv
,
1647 for (i
= 0; i
< sizeof(nbrflags
) / sizeof(struct vnflags
); i
++)
1648 if (a
->al_flags
& nbrflags
[i
].vn_flag
)
1649 fprintf(fp
, " %s", nbrflags
[i
].vn_name
);
1650 fprintf(fp
, " up %s\n", scaletime(now
- a
->al_ctime
));
1651 /*fprintf(fp, " #routes %d\n", a->al_nroutes);*/
1655 label
= "group host (time left):";
1656 for (a
= v
->uv_groups
; a
!= NULL
; a
= a
->al_next
) {
1657 fprintf(fp
, " %23s %-15s %-15s (%s)\n",
1659 inet_fmt(a
->al_addr
, s1
),
1660 inet_fmt(a
->al_reporter
, s2
),
1661 scaletime(timer_leftTimer(a
->al_timerid
)));
1664 label
= "boundaries:";
1665 for (acl
= v
->uv_acl
; acl
!= NULL
; acl
= acl
->acl_next
) {
1666 fprintf(fp
, " %11s %-18s\n", label
,
1667 inet_fmts(acl
->acl_addr
, acl
->acl_mask
, s1
));
1671 struct vf_element
*vfe
;
1674 sprintf(lbuf
, "%5s %7s filter:",
1675 v
->uv_filter
->vf_flags
& VFF_BIDIR
? "bidir"
1677 v
->uv_filter
->vf_type
== VFT_ACCEPT
? "accept"
1680 for (vfe
= v
->uv_filter
->vf_filter
;
1681 vfe
!= NULL
; vfe
= vfe
->vfe_next
) {
1682 fprintf(fp
, " %23s %-18s%s\n",
1684 inet_fmts(vfe
->vfe_addr
, vfe
->vfe_mask
, s1
),
1685 vfe
->vfe_flags
& VFEF_EXACT
? " (exact)" : "");
1689 if (!(v
->uv_flags
& (VIFF_TUNNEL
|VIFF_DOWN
|VIFF_DISABLED
))) {
1690 fprintf(fp
, " IGMP querier: ");
1691 if (v
->uv_querier
== NULL
)
1692 if (v
->uv_flags
& VIFF_QUERIER
)
1693 fprintf(fp
, "%-18s (this system)\n",
1694 inet_fmt(v
->uv_lcl_addr
, s1
));
1696 fprintf(fp
, "NONE - querier election failure?\n");
1698 fprintf(fp
, "%-18s up %s last heard %s ago\n",
1699 inet_fmt(v
->uv_querier
->al_addr
, s1
),
1700 scaletime(now
- v
->uv_querier
->al_ctime
),
1701 scaletime(v
->uv_querier
->al_timer
));
1703 if (v
->uv_flags
& VIFF_BLASTER
)
1704 fprintf(fp
, " blasterbuf size: %dk\n",
1705 v
->uv_blasterlen
/ 1024);
1706 fprintf(fp
, " Nbr bitmaps: 0x%08lx%08lx\n",/*XXX*/
1707 v
->uv_nbrmap
.hi
, v
->uv_nbrmap
.lo
);
1708 if (v
->uv_prune_lifetime
!= 0)
1709 fprintf(fp
, " Prune Lifetime: %d seconds\n",
1710 v
->uv_prune_lifetime
);
1714 if (ioctl(udp_socket
, SIOCGETVIFCNT
, (char *)&v_req
) < 0) {
1715 dolog(LOG_WARNING
, errno
,
1716 "SIOCGETVIFCNT fails on vif %d", vifi
);
1718 fprintf(fp
, " pkts/bytes in : %lu/%lu\n",
1719 v_req
.icount
, v_req
.ibytes
);
1720 fprintf(fp
, " pkts/bytes out: %lu/%lu\n",
1721 v_req
.ocount
, v_req
.obytes
);
1729 * Time out record of a group membership on a vif
1734 cbk_t
*cbk
= (cbk_t
*)arg
;
1735 vifi_t vifi
= cbk
->vifi
;
1736 struct uvif
*v
= &uvifs
[vifi
];
1737 struct listaddr
*a
, **anp
, *g
= cbk
->g
;
1741 * delete all kernel cache entries with this group
1744 DeleteTimer(g
->al_query
);
1746 delete_lclgrp(vifi
, g
->al_addr
);
1748 anp
= &(v
->uv_groups
);
1749 while ((a
= *anp
) != NULL
) {
1762 * Set a timer to delete the record of a group membership on a vif.
1765 SetTimer(vifi_t vifi
, struct listaddr
*g
)
1769 cbk
= (cbk_t
*) malloc(sizeof(cbk_t
));
1772 return timer_setTimer(g
->al_timer
, DelVif
, cbk
);
1776 * Delete a timer that was set above.
1781 timer_clearTimer(id
);
1786 * Send a group-specific query.
1789 SendQuery(void *arg
)
1791 cbk_t
*cbk
= (cbk_t
*)arg
;
1792 struct uvif
*v
= &uvifs
[cbk
->vifi
];
1794 send_igmp(v
->uv_lcl_addr
, cbk
->g
->al_addr
,
1795 IGMP_MEMBERSHIP_QUERY
,
1796 cbk
->q_time
, cbk
->g
->al_addr
, 0);
1797 cbk
->g
->al_query
= 0;
1802 * Set a timer to send a group-specific query.
1805 SetQueryTimer(struct listaddr
*g
, vifi_t vifi
, int to_expire
, int q_time
)
1809 cbk
= (cbk_t
*) malloc(sizeof(cbk_t
));
1811 cbk
->q_time
= q_time
;
1813 return timer_setTimer(to_expire
, SendQuery
, cbk
);