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 $
21 struct uvif uvifs
[MAXVIFS
]; /* array of virtual interfaces */
22 vifi_t numvifs
; /* number of vifs in use */
23 int vifs_down
; /* 1=>some interfaces are down */
24 int phys_vif
; /* An enabled vif */
25 int udp_socket
; /* Since the honkin' kernel doesn't support */
26 /* ioctls on raw IP sockets, we need a UDP */
27 /* socket as well as our IGMP (raw) socket. */
29 int vifs_with_neighbors
; /* == 1 if I am a leaf */
34 struct listaddr
*nbrs
[MAXNBRS
]; /* array of neighbors */
43 * Forward declarations.
45 static void start_vif(vifi_t vifi
);
46 static void start_vif2(vifi_t vifi
);
47 static void stop_vif(vifi_t vifi
);
48 static void age_old_hosts(void);
49 static void send_probe_on_vif(struct uvif
*v
);
50 static void send_query(struct uvif
*v
);
51 static int info_version(char *p
, int plen
);
52 static void DelVif(void *arg
);
53 static int SetTimer(vifi_t vifi
, struct listaddr
*g
);
54 static int DeleteTimer(int id
);
55 static void SendQuery(void *arg
);
56 static int SetQueryTimer(struct listaddr
*g
, vifi_t vifi
, int to_expire
,
61 * Initialize the virtual interfaces, but do not install
62 * them in the kernel. Start routing on all vifs that are
63 * not down or disabled.
70 int enabled_vifs
, enabled_phyints
;
71 extern char *configfilename
;
74 vifs_with_neighbors
= 0;
78 * Configure the vifs based on the interface configuration of the
79 * the kernel and the contents of the configuration file.
80 * (Open a UDP socket for ioctl use in the config procedures if
81 * the kernel can't handle IOCTL's on the IGMP socket.)
83 #ifdef IOCTL_OK_ON_RAW_SOCKET
84 udp_socket
= igmp_socket
;
86 if ((udp_socket
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0)
87 dolog(LOG_ERR
, errno
, "UDP socket");
89 dolog(LOG_INFO
,0,"Getting vifs from kernel interfaces");
90 config_vifs_from_kernel();
91 dolog(LOG_INFO
,0,"Getting vifs from %s",configfilename
);
92 config_vifs_from_file();
95 * Quit if there are fewer than two enabled vifs.
100 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
101 if (!(v
->uv_flags
& VIFF_DISABLED
)) {
103 if (!(v
->uv_flags
& VIFF_TUNNEL
)) {
110 if (enabled_vifs
< 2)
111 dolog(LOG_ERR
, 0, "can't forward: %s",
112 enabled_vifs
== 0 ? "no enabled vifs" : "only one enabled vif");
114 if (enabled_phyints
== 0)
115 dolog(LOG_WARNING
, 0,
116 "no enabled interfaces, forwarding via tunnels only");
118 dolog(LOG_INFO
, 0, "Installing vifs in mrouted...");
119 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
120 if (!(v
->uv_flags
& VIFF_DISABLED
)) {
121 if (!(v
->uv_flags
& VIFF_DOWN
)) {
122 if (v
->uv_flags
& VIFF_TUNNEL
)
123 dolog(LOG_INFO
, 0, "vif #%d, tunnel %s -> %s", vifi
,
124 inet_fmt(v
->uv_lcl_addr
, s1
),
125 inet_fmt(v
->uv_rmt_addr
, s2
));
127 dolog(LOG_INFO
, 0, "vif #%d, phyint %s", vifi
,
128 inet_fmt(v
->uv_lcl_addr
, s1
));
130 } else dolog(LOG_INFO
, 0,
131 "%s is not yet up; vif #%u not in service",
138 * Initialize the passed vif with all appropriate default values.
139 * "t" is true if a tunnel, or false if a phyint.
142 zero_vif(struct uvif
*v
, int t
)
146 v
->uv_metric
= DEFAULT_METRIC
;
148 v
->uv_threshold
= DEFAULT_THRESHOLD
;
149 v
->uv_rate_limit
= t
? DEFAULT_TUN_RATE_LIMIT
: DEFAULT_PHY_RATE_LIMIT
;
152 v
->uv_dst_addr
= t
? 0 : dvmrp_group
;
154 v
->uv_subnetmask
= 0;
155 v
->uv_subnetbcast
= 0;
156 v
->uv_name
[0] = '\0';
158 v
->uv_neighbors
= NULL
;
159 NBRM_CLRALL(v
->uv_nbrmap
);
160 v
->uv_querier
= NULL
;
161 v
->uv_igmpv1_warn
= 0;
162 v
->uv_prune_lifetime
= 0;
163 v
->uv_leaf_timer
= 0;
167 v
->uv_blasterbuf
= NULL
;
168 v
->uv_blastercur
= NULL
;
169 v
->uv_blasterend
= NULL
;
170 v
->uv_blasterlen
= 0;
171 v
->uv_blastertimer
= 0;
178 * Start routing on all virtual interfaces that are not down or
179 * administratively disabled.
182 init_installvifs(void)
187 dolog(LOG_INFO
, 0, "Installing vifs in kernel...");
188 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
189 if (!(v
->uv_flags
& VIFF_DISABLED
)) {
190 if (!(v
->uv_flags
& VIFF_DOWN
)) {
191 if (v
->uv_flags
& VIFF_TUNNEL
)
192 dolog(LOG_INFO
, 0, "vif #%d, tunnel %s -> %s", vifi
,
193 inet_fmt(v
->uv_lcl_addr
, s1
),
194 inet_fmt(v
->uv_rmt_addr
, s2
));
196 dolog(LOG_INFO
, 0, "vif #%d, phyint %s", vifi
,
197 inet_fmt(v
->uv_lcl_addr
, s1
));
198 k_add_vif(vifi
, &uvifs
[vifi
]);
199 } else dolog(LOG_INFO
, 0,
200 "%s is not yet up; vif #%u not in service",
207 * See if any interfaces have changed from up state to down, or vice versa,
208 * including any non-multicast-capable interfaces that are in use as local
209 * tunnel end-points. Ignore interfaces that have been administratively
213 check_vif_state(void)
218 static int checking_vifs
= 0;
221 * If we get an error while checking, (e.g. two interfaces go down
222 * at once, and we decide to send a prune out one of the failed ones)
223 * then don't go into an infinite loop!
230 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
232 if (v
->uv_flags
& VIFF_DISABLED
) continue;
234 strncpy(ifr
.ifr_name
, v
->uv_name
, IFNAMSIZ
);
235 if (ioctl(udp_socket
, SIOCGIFFLAGS
, (char *)&ifr
) < 0)
236 dolog(LOG_ERR
, errno
,
237 "ioctl SIOCGIFFLAGS for %s", ifr
.ifr_name
);
239 if (v
->uv_flags
& VIFF_DOWN
) {
240 if (ifr
.ifr_flags
& IFF_UP
) {
242 "%s has come up; vif #%u now in service",
244 v
->uv_flags
&= ~VIFF_DOWN
;
247 else vifs_down
= TRUE
;
250 if (!(ifr
.ifr_flags
& IFF_UP
)) {
252 "%s has gone down; vif #%u taken out of service",
255 v
->uv_flags
|= VIFF_DOWN
;
264 * Send a DVMRP message on the specified vif. If DVMRP messages are
265 * to be encapsulated and sent "inside" the tunnel, use the special
266 * encapsulator. If it's not a tunnel or DVMRP messages are to be
267 * sent "beside" the tunnel, as required by earlier versions of mrouted,
268 * then just send the message.
271 send_on_vif(struct uvif
*v
, u_int32 dst
, int code
, int datalen
)
273 u_int32 group
= htonl(MROUTED_LEVEL
|
274 ((v
->uv_flags
& VIFF_LEAF
) ? 0 : LEAF_FLAGS
));
277 * The UNIX kernel will not decapsulate unicasts.
278 * Therefore, we don't send encapsulated unicasts.
280 if ((v
->uv_flags
& (VIFF_TUNNEL
|VIFF_OTUNNEL
)) == VIFF_TUNNEL
&&
281 ((dst
== 0) || IN_MULTICAST(ntohl(dst
))))
282 send_ipip(v
->uv_lcl_addr
, dst
? dst
: dvmrp_group
, IGMP_DVMRP
,
283 code
, group
, datalen
, v
);
285 send_igmp(v
->uv_lcl_addr
, dst
? dst
: v
->uv_dst_addr
, IGMP_DVMRP
,
286 code
, group
, datalen
);
291 * Send a probe message on vif v
294 send_probe_on_vif(struct uvif
*v
)
298 struct listaddr
*nbr
;
301 if ((v
->uv_flags
& VIFF_PASSIVE
&& v
->uv_neighbors
== NULL
) ||
302 (v
->uv_flags
& VIFF_FORCE_LEAF
))
305 p
= send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
;
307 for (i
= 0; i
< 4; i
++)
308 *p
++ = ((char *)&(dvmrp_genid
))[i
];
312 * add the neighbor list on the interface to the message
314 nbr
= v
->uv_neighbors
;
317 for (i
= 0; i
< 4; i
++)
318 *p
++ = ((char *)&nbr
->al_addr
)[i
];
323 send_on_vif(v
, 0, DVMRP_PROBE
, datalen
);
327 send_query(struct uvif
*v
)
330 dolog(LOG_DEBUG
, 0, "sending %squery on vif %ld",
331 (v
->uv_flags
& VIFF_IGMPV1
) ? "v1 " : "",
333 send_igmp(v
->uv_lcl_addr
, allhosts_group
,
334 IGMP_MEMBERSHIP_QUERY
,
335 (v
->uv_flags
& VIFF_IGMPV1
) ? 0 :
336 IGMP_MAX_HOST_REPORT_DELAY
* IGMP_TIMER_SCALE
, 0, 0);
340 * Add a vifi to the kernel and start routing on it.
343 start_vif(vifi_t vifi
)
346 * Install the interface in the kernel's vif structure.
348 k_add_vif(vifi
, &uvifs
[vifi
]);
354 * Add a vifi to all the user-level data structures but don't add
355 * it to the kernel yet.
358 start_vif2(vifi_t vifi
)
365 src
= v
->uv_lcl_addr
;
368 * Update the existing route entries to take into account the new vif.
370 add_vif_to_routes(vifi
);
372 if (!(v
->uv_flags
& VIFF_TUNNEL
)) {
374 * Join the DVMRP multicast group on the interface.
375 * (This is not strictly necessary, since the kernel promiscuously
376 * receives IGMP packets addressed to ANY IP multicast group while
377 * multicast routing is enabled. However, joining the group allows
378 * this host to receive non-IGMP packets as well, such as 'pings'.)
380 k_join(dvmrp_group
, src
);
383 * Join the ALL-ROUTERS multicast group on the interface.
384 * This allows mtrace requests to loop back if they are run
385 * on the multicast router.
387 k_join(allrtrs_group
, src
);
390 * Install an entry in the routing table for the subnet to which
391 * the interface is connected.
393 start_route_updates();
394 update_route(v
->uv_subnet
, v
->uv_subnetmask
, 0, 0, vifi
, NULL
);
395 for (p
= v
->uv_addrs
; p
; p
= p
->pa_next
) {
396 start_route_updates();
397 update_route(p
->pa_subnet
, p
->pa_subnetmask
, 0, 0, vifi
, NULL
);
401 * Until neighbors are discovered, assume responsibility for sending
402 * periodic group membership queries to the subnet. Send the first
405 v
->uv_flags
|= VIFF_QUERIER
;
407 dolog(LOG_DEBUG
, 0, "assuming querier duties on vif %d", vifi
);
411 v
->uv_leaf_timer
= LEAF_CONFIRMATION_TIME
;
414 * Send a probe via the new vif to look for neighbors.
416 send_probe_on_vif(v
);
420 * Stop routing on the specified virtual interface.
423 stop_vif(vifi_t vifi
)
431 if (!(v
->uv_flags
& VIFF_TUNNEL
)) {
433 * Depart from the DVMRP multicast group on the interface.
435 k_leave(dvmrp_group
, v
->uv_lcl_addr
);
438 * Depart from the ALL-ROUTERS multicast group on the interface.
440 k_leave(allrtrs_group
, v
->uv_lcl_addr
);
443 * Update the entry in the routing table for the subnet to which
444 * the interface is connected, to take into account the interface
447 start_route_updates();
448 update_route(v
->uv_subnet
, v
->uv_subnetmask
, UNREACHABLE
, 0, vifi
, NULL
);
449 for (p
= v
->uv_addrs
; p
; p
= p
->pa_next
) {
450 start_route_updates();
451 update_route(p
->pa_subnet
, p
->pa_subnetmask
, UNREACHABLE
, 0, vifi
, NULL
);
455 * Discard all group addresses. (No need to tell kernel;
456 * the k_del_vif() call, below, will clean up kernel state.)
458 while (v
->uv_groups
!= NULL
) {
460 v
->uv_groups
= a
->al_next
;
465 dolog(LOG_DEBUG
, 0, "releasing querier duties on vif %d", vifi
);
466 v
->uv_flags
&= ~VIFF_QUERIER
;
470 * Update the existing route entries to take into account the vif failure.
472 delete_vif_from_routes(vifi
);
475 * Delete the interface from the kernel's vif structure.
480 * Discard all neighbor addresses.
482 if (!NBRM_ISEMPTY(v
->uv_nbrmap
))
483 vifs_with_neighbors
--;
485 while (v
->uv_neighbors
!= NULL
) {
487 v
->uv_neighbors
= a
->al_next
;
488 nbrs
[a
->al_index
] = NULL
;
491 NBRM_CLRALL(v
->uv_nbrmap
);
496 * stop routing on all vifs
506 for (vifi
= 0; vifi
< numvifs
; vifi
++) {
508 while (v
->uv_groups
!= NULL
) {
510 v
->uv_groups
= a
->al_next
;
513 while (v
->uv_neighbors
!= NULL
) {
515 v
->uv_neighbors
= a
->al_next
;
516 nbrs
[a
->al_index
] = NULL
;
519 while (v
->uv_acl
!= NULL
) {
521 v
->uv_acl
= acl
->acl_next
;
529 * Find the virtual interface from which an incoming packet arrived,
530 * based on the packet's source and destination IP addresses.
533 find_vif(u_int32 src
, u_int32 dst
)
539 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
540 if (!(v
->uv_flags
& (VIFF_DOWN
|VIFF_DISABLED
))) {
541 if (v
->uv_flags
& VIFF_TUNNEL
) {
542 if (src
== v
->uv_rmt_addr
&& (dst
== v
->uv_lcl_addr
||
547 if ((src
& v
->uv_subnetmask
) == v
->uv_subnet
&&
548 ((v
->uv_subnetmask
== 0xffffffff) ||
549 (src
!= v
->uv_subnetbcast
)))
551 for (p
=v
->uv_addrs
; p
; p
=p
->pa_next
) {
552 if ((src
& p
->pa_subnetmask
) == p
->pa_subnet
&&
553 ((p
->pa_subnetmask
== 0xffffffff) ||
554 (src
!= p
->pa_subnetbcast
)))
571 * Decrement the old-hosts-present timer for each
572 * active group on each vif.
574 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++)
575 for (g
= v
->uv_groups
; g
!= NULL
; g
= g
->al_next
)
582 * Send group membership queries on each interface for which I am querier.
583 * Note that technically, there should be a timer per interface, as the
584 * dynamics of querier election can cause the "right" time to send a
585 * query to be different on different interfaces. However, this simple
586 * implementation only ever sends queries sooner than the "right" time,
587 * so can not cause loss of membership (but can send more packets than
596 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
597 if (v
->uv_flags
& VIFF_QUERIER
) {
605 * Process an incoming host membership query. Warn about
606 * IGMP version mismatches, perform querier election, and
607 * handle group-specific queries when we're not the querier.
610 accept_membership_query(u_int32 src
, u_int32 dst
, u_int32 group
, int tmo
)
615 if ((vifi
= find_vif(src
, dst
)) == NO_VIF
||
616 (uvifs
[vifi
].uv_flags
& VIFF_TUNNEL
)) {
618 "ignoring group membership query from non-adjacent host %s",
625 if ((tmo
== 0 && !(v
->uv_flags
& VIFF_IGMPV1
)) ||
626 (tmo
!= 0 && (v
->uv_flags
& VIFF_IGMPV1
))) {
630 * Exponentially back-off warning rate
632 i
= ++v
->uv_igmpv1_warn
;
633 while (i
&& !(i
& 1))
636 dolog(LOG_WARNING
, 0, "%s %s on vif %d, %s",
637 tmo
== 0 ? "Received IGMPv1 report from"
638 : "Received IGMPv2 report from",
641 tmo
== 0 ? "please configure vif for IGMPv1"
642 : "but I am configured for IGMPv1");
645 if (v
->uv_querier
== NULL
|| v
->uv_querier
->al_addr
!= src
) {
648 * - A query from a new querier, with a lower source address
649 * than the current querier (who might be me)
650 * - A query from a new router that just started up and doesn't
651 * know who the querier is.
653 if (ntohl(src
) < (v
->uv_querier
? ntohl(v
->uv_querier
->al_addr
)
654 : ntohl(v
->uv_lcl_addr
))) {
656 dolog(LOG_DEBUG
, 0, "new querier %s (was %s) on vif %d",
658 v
->uv_querier
? inet_fmt(v
->uv_querier
->al_addr
, s2
) :
660 if (!v
->uv_querier
) {
661 v
->uv_querier
= (struct listaddr
*)
662 malloc(sizeof(struct listaddr
));
663 v
->uv_flags
&= ~VIFF_QUERIER
;
665 time(&v
->uv_querier
->al_ctime
);
666 v
->uv_querier
->al_addr
= src
;
669 dolog(LOG_DEBUG
, 0, "ignoring query from %s; querier on vif %d is still %s",
670 inet_fmt(src
, s1
), vifi
,
671 v
->uv_querier
? inet_fmt(v
->uv_querier
->al_addr
, s2
) :
679 * Reset the timer since we've received a query.
681 if (v
->uv_querier
&& src
== v
->uv_querier
->al_addr
)
682 v
->uv_querier
->al_timer
= 0;
685 * If this is a Group-Specific query which we did not source,
686 * we must set our membership timer to [Last Member Query Count] *
687 * the [Max Response Time] in the packet.
689 if (!(v
->uv_flags
& (VIFF_IGMPV1
|VIFF_QUERIER
)) && group
!= 0 &&
690 src
!= v
->uv_lcl_addr
) {
695 "%s for %s from %s on vif %d, timer %d",
696 "Group-specific membership query",
697 inet_fmt(group
, s2
), inet_fmt(src
, s1
), vifi
, tmo
);
699 for (g
= v
->uv_groups
; g
!= NULL
; g
= g
->al_next
) {
700 if (group
== g
->al_addr
&& g
->al_query
== 0) {
701 /* setup a timeout to remove the group membership */
703 g
->al_timerid
= DeleteTimer(g
->al_timerid
);
704 g
->al_timer
= IGMP_LAST_MEMBER_QUERY_COUNT
*
705 tmo
/ IGMP_TIMER_SCALE
;
706 /* use al_query to record our presence in last-member state */
708 g
->al_timerid
= SetTimer(vifi
, g
);
711 "timer for grp %s on vif %d set to %lu",
712 inet_fmt(group
, s2
), vifi
, g
->al_timer
);
720 * Process an incoming group membership report.
723 accept_group_report(u_int32 src
, u_int32 dst
, u_int32 group
, int r_type
)
729 if ((vifi
= find_vif(src
, dst
)) == NO_VIF
||
730 (uvifs
[vifi
].uv_flags
& VIFF_TUNNEL
)) {
732 "ignoring group membership report from non-adjacent host %s",
740 * Look for the group in our group list; if found, reset its timer.
742 for (g
= v
->uv_groups
; g
!= NULL
; g
= g
->al_next
) {
743 if (group
== g
->al_addr
) {
744 if (r_type
== IGMP_V1_MEMBERSHIP_REPORT
)
745 g
->al_old
= OLD_AGE_THRESHOLD
;
747 g
->al_reporter
= src
;
749 /** delete old timers, set a timer for expiration **/
750 g
->al_timer
= IGMP_GROUP_MEMBERSHIP_INTERVAL
;
752 g
->al_query
= DeleteTimer(g
->al_query
);
754 g
->al_timerid
= DeleteTimer(g
->al_timerid
);
755 g
->al_timerid
= SetTimer(vifi
, g
);
761 * If not found, add it to the list and update kernel cache.
764 g
= (struct listaddr
*)malloc(sizeof(struct listaddr
));
766 dolog(LOG_ERR
, 0, "ran out of memory"); /* fatal */
769 if (r_type
== IGMP_V1_MEMBERSHIP_REPORT
)
770 g
->al_old
= OLD_AGE_THRESHOLD
;
774 /** set a timer for expiration **/
776 g
->al_timer
= IGMP_GROUP_MEMBERSHIP_INTERVAL
;
777 g
->al_reporter
= src
;
778 g
->al_timerid
= SetTimer(vifi
, g
);
779 g
->al_next
= v
->uv_groups
;
783 update_lclgrp(vifi
, group
);
787 * Check if a graft is necessary for this group
789 chkgrp_graft(vifi
, group
);
793 * Process an incoming IGMPv2 Leave Group message.
796 accept_leave_message(u_int32 src
, u_int32 dst
, u_int32 group
)
802 if ((vifi
= find_vif(src
, dst
)) == NO_VIF
||
803 (uvifs
[vifi
].uv_flags
& VIFF_TUNNEL
)) {
805 "ignoring group leave report from non-adjacent host %s",
812 if (!(v
->uv_flags
& VIFF_QUERIER
) || (v
->uv_flags
& VIFF_IGMPV1
))
816 * Look for the group in our group list in order to set up a short-timeout
819 for (g
= v
->uv_groups
; g
!= NULL
; g
= g
->al_next
) {
820 if (group
== g
->al_addr
) {
823 "[vif.c, _accept_leave_message] %d %lu \n",
824 g
->al_old
, g
->al_query
);
826 /* Ignore the leave message if there are old hosts present */
830 /* still waiting for a reply to a query, ignore the leave */
834 /** delete old timer set a timer for expiration **/
836 g
->al_timerid
= DeleteTimer(g
->al_timerid
);
838 #if IGMP_LAST_MEMBER_QUERY_COUNT != 2
839 This code needs to be updated to keep a counter of the number
840 of queries remaining
.
842 /** send a group specific querry **/
843 g
->al_timer
= IGMP_LAST_MEMBER_QUERY_INTERVAL
*
844 (IGMP_LAST_MEMBER_QUERY_COUNT
+ 1);
845 send_igmp(v
->uv_lcl_addr
, g
->al_addr
,
846 IGMP_MEMBERSHIP_QUERY
,
847 IGMP_LAST_MEMBER_QUERY_INTERVAL
* IGMP_TIMER_SCALE
,
849 g
->al_query
= SetQueryTimer(g
, vifi
,
850 IGMP_LAST_MEMBER_QUERY_INTERVAL
,
851 IGMP_LAST_MEMBER_QUERY_INTERVAL
* IGMP_TIMER_SCALE
);
852 g
->al_timerid
= SetTimer(vifi
, g
);
860 * Send a periodic probe on all vifs.
861 * Useful to determine one-way interfaces.
862 * Detect neighbor loss faster.
865 probe_for_neighbors(void)
870 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
871 if (!(v
->uv_flags
& (VIFF_DOWN
|VIFF_DISABLED
))) {
872 send_probe_on_vif(v
);
879 * Send a list of all of our neighbors to the requestor, `src'.
882 accept_neighbor_request(u_int32 src
, u_int32 dst
)
889 u_int32 temp_addr
, them
= src
;
891 #define PUT_ADDR(a) temp_addr = ntohl(a); \
892 *p++ = temp_addr >> 24; \
893 *p++ = (temp_addr >> 16) & 0xFF; \
894 *p++ = (temp_addr >> 8) & 0xFF; \
895 *p++ = temp_addr & 0xFF;
897 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
900 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
901 if (v
->uv_flags
& VIFF_DISABLED
)
906 for (la
= v
->uv_neighbors
; la
; la
= la
->al_next
) {
908 /* Make sure that there's room for this neighbor... */
909 if (datalen
+ (ncount
== NULL
? 4 + 3 + 4 : 4) > MAX_DVMRP_DATA_LEN
) {
910 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS
,
911 htonl(MROUTED_LEVEL
), datalen
);
912 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
917 /* Put out the header for this neighbor list... */
918 if (ncount
== NULL
) {
919 PUT_ADDR(v
->uv_lcl_addr
);
921 *p
++ = v
->uv_threshold
;
927 PUT_ADDR(la
->al_addr
);
934 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS
,
935 htonl(MROUTED_LEVEL
), datalen
);
939 * Send a list of all of our neighbors to the requestor, `src'.
942 accept_neighbor_request2(u_int32 src
, u_int32 dst
)
951 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
954 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
955 u_short vflags
= v
->uv_flags
;
958 if (vflags
& VIFF_TUNNEL
)
959 rflags
|= DVMRP_NF_TUNNEL
;
960 if (vflags
& VIFF_SRCRT
)
961 rflags
|= DVMRP_NF_SRCRT
;
962 if (vflags
& VIFF_DOWN
)
963 rflags
|= DVMRP_NF_DOWN
;
964 if (vflags
& VIFF_DISABLED
)
965 rflags
|= DVMRP_NF_DISABLED
;
966 if (vflags
& VIFF_QUERIER
)
967 rflags
|= DVMRP_NF_QUERIER
;
968 if (vflags
& VIFF_LEAF
)
969 rflags
|= DVMRP_NF_LEAF
;
971 la
= v
->uv_neighbors
;
974 * include down & disabled interfaces and interfaces on
977 if (rflags
& DVMRP_NF_TUNNEL
)
978 rflags
|= DVMRP_NF_DOWN
;
979 if (datalen
> MAX_DVMRP_DATA_LEN
- 12) {
980 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS2
,
981 htonl(MROUTED_LEVEL
), datalen
);
982 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
985 *(u_int
*)p
= v
->uv_lcl_addr
;
988 *p
++ = v
->uv_threshold
;
991 *(u_int
*)p
= v
->uv_rmt_addr
;
995 for ( ; la
; la
= la
->al_next
) {
996 /* Make sure that there's room for this neighbor... */
997 if (datalen
+ (ncount
== NULL
? 4+4+4 : 4) > MAX_DVMRP_DATA_LEN
) {
998 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS2
,
999 htonl(MROUTED_LEVEL
), datalen
);
1000 p
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
1004 /* Put out the header for this neighbor list... */
1005 if (ncount
== NULL
) {
1006 /* If it's a one-way tunnel, mark it down. */
1007 if (rflags
& DVMRP_NF_TUNNEL
&& la
->al_flags
& NBRF_ONEWAY
)
1008 rflags
|= DVMRP_NF_DOWN
;
1009 *(u_int
*)p
= v
->uv_lcl_addr
;
1011 *p
++ = v
->uv_metric
;
1012 *p
++ = v
->uv_threshold
;
1018 /* Don't report one-way peering on phyint at all */
1019 if (!(rflags
& DVMRP_NF_TUNNEL
) && la
->al_flags
& NBRF_ONEWAY
)
1021 *(u_int
*)p
= la
->al_addr
;
1027 *(u_int
*)p
= v
->uv_rmt_addr
;
1035 send_igmp(INADDR_ANY
, them
, IGMP_DVMRP
, DVMRP_NEIGHBORS2
,
1036 htonl(MROUTED_LEVEL
), datalen
);
1040 accept_info_request(u_int32 src
, u_int32 dst
, u_char
*p
, int datalen
)
1046 q
= (u_char
*) (send_buf
+ MIN_IP_HEADER_LEN
+ IGMP_MINLEN
);
1048 /* To be general, this must deal properly with breaking up over-sized
1049 * packets. That implies passing a length to each function, and
1050 * allowing each function to request to be called again. Right now,
1051 * we're only implementing the one thing we are positive will fit into
1052 * a single packet, so we wimp out.
1054 while (datalen
> 0) {
1057 case DVMRP_INFO_VERSION
:
1058 len
= info_version(q
, RECV_BUF_SIZE
-(q
-(u_char
*)send_buf
));
1061 case DVMRP_INFO_NEIGHBORS
:
1063 dolog(LOG_INFO
, 0, "ignoring unknown info type %d", *p
);
1069 len
= (*(p
+1) + 1) * 4;
1075 send_igmp(INADDR_ANY
, src
, IGMP_DVMRP
, DVMRP_INFO_REPLY
,
1076 htonl(MROUTED_LEVEL
), outlen
);
1080 * Information response -- return version string
1083 info_version(char *p
, int plen
)
1086 extern char versionstring
[];
1088 *p
++ = DVMRP_INFO_VERSION
;
1089 p
++; /* skip over length */
1090 *p
++ = 0; /* zero out */
1091 *p
++ = 0; /* reserved fields */
1092 strncpy(p
, versionstring
, plen
- 4);
1095 len
= strlen(versionstring
);
1096 return ((len
+ 3) / 4);
1100 * Process an incoming neighbor-list message.
1103 accept_neighbors(u_int32 src
, u_int32 dst
, u_char
*p
, int datalen
,
1106 dolog(LOG_INFO
, 0, "ignoring spurious DVMRP neighbor list from %s to %s",
1107 inet_fmt(src
, s1
), inet_fmt(dst
, s2
));
1112 * Process an incoming neighbor-list message.
1115 accept_neighbors2(u_int32 src
, u_int32 dst
, u_char
*p
, int datalen
,
1119 dolog(LOG_DEBUG
, 0, "ignoring spurious DVMRP neighbor list2 from %s to %s",
1120 inet_fmt(src
, s1
), inet_fmt(dst
, s2
));
1124 * Process an incoming info reply message.
1127 accept_info_reply(u_int32 src
, u_int32 dst
, u_char
*p
, int datalen
)
1130 dolog(LOG_DEBUG
, 0, "ignoring spurious DVMRP info reply from %s to %s",
1131 inet_fmt(src
, s1
), inet_fmt(dst
, s2
));
1136 * Update the neighbor entry for neighbor 'addr' on vif 'vifi'.
1137 * 'msgtype' is the type of DVMRP message received from the neighbor.
1138 * Return the neighbor entry if 'addr' is a valid neighbor, FALSE otherwise.
1141 update_neighbor(vifi_t vifi
, u_int32 addr
, int msgtype
, char *p
, int datalen
,
1146 int pv
= level
& 0xff;
1147 int mv
= (level
>> 8) & 0xff;
1149 int in_router_list
= 0;
1152 u_int32 send_tables
= 0;
1154 int do_reset
= FALSE
;
1159 * Confirm that 'addr' is a valid neighbor address on vif 'vifi'.
1160 * IT IS ASSUMED that this was preceded by a call to find_vif(), which
1161 * checks that 'addr' is either a valid remote tunnel endpoint or a
1162 * non-broadcast address belonging to a directly-connected subnet.
1163 * Therefore, here we check only that 'addr' is not our own address
1164 * (due to an impostor or erroneous loopback) or an address of the form
1165 * {subnet,0} ("the unknown host"). These checks are not performed in
1166 * find_vif() because those types of address are acceptable for some
1167 * types of IGMP message (such as group membership reports).
1169 if (!(v
->uv_flags
& VIFF_TUNNEL
) &&
1170 (addr
== v
->uv_lcl_addr
||
1171 addr
== v
->uv_subnet
)) {
1172 dolog(LOG_WARNING
, 0,
1173 "received DVMRP message from %s: %s",
1174 (addr
== v
->uv_lcl_addr
) ? "self (check device loopback)" :
1175 "'the unknown host'",
1176 inet_fmt(addr
, s1
));
1181 * Ignore all neighbors on vifs forced into leaf mode
1183 if (v
->uv_flags
& VIFF_FORCE_LEAF
) {
1188 * mrouted's version 3.3 and later include the generation ID
1189 * and the list of neighbors on the vif in their probe messages.
1191 if (msgtype
== DVMRP_PROBE
&& ((pv
== 3 && mv
> 2) ||
1192 (pv
> 3 && pv
< 10))) {
1195 IF_DEBUG(DEBUG_PEER
)
1196 dolog(LOG_DEBUG
, 0, "checking probe from %s (%d.%d) on vif %d",
1197 inet_fmt(addr
, s1
), pv
, mv
, vifi
);
1200 dolog(LOG_WARNING
, 0,
1201 "received truncated probe message from %s (len %d)",
1202 inet_fmt(addr
, s1
), datalen
);
1208 for (i
= 0; i
< 4; i
++)
1209 ((char *)&genid
)[i
] = *p
++;
1212 while (datalen
> 0) {
1214 dolog(LOG_WARNING
, 0,
1215 "received truncated probe message from %s (len %d)",
1216 inet_fmt(addr
, s1
), datalen
);
1219 for (i
= 0; i
< 4; i
++)
1220 ((char *)&router
)[i
] = *p
++;
1223 if (router
== v
->uv_lcl_addr
) {
1230 if ((pv
== 3 && mv
== 255) || (pv
> 3 && pv
< 10))
1234 * Look for addr in list of neighbors.
1236 for (n
= v
->uv_neighbors
; n
!= NULL
; n
= n
->al_next
) {
1237 if (addr
== n
->al_addr
) {
1246 * If this neighbor follows the DVMRP spec, start the probe
1247 * handshake. If not, then it doesn't require the probe
1248 * handshake, so establish the peering immediately.
1250 if (dvmrpspec
&& (msgtype
!= DVMRP_PROBE
))
1253 for (i
= 0; i
< MAXNBRS
; i
++)
1254 if (nbrs
[i
] == NULL
)
1258 /* XXX This is a severe new restriction. */
1259 /* XXX want extensible bitmaps! */
1260 dolog(LOG_ERR
, 0, "Can't handle %luth neighbor %s on vif %d!",
1261 MAXNBRS
, inet_fmt(addr
, s1
), vifi
);
1266 * Add it to our list of neighbors.
1268 IF_DEBUG(DEBUG_PEER
)
1269 dolog(LOG_DEBUG
, 0, "New neighbor %s on vif %d v%d.%d nf 0x%02x idx %d",
1270 inet_fmt(addr
, s1
), vifi
, level
& 0xff, (level
>> 8) & 0xff,
1271 (level
>> 16) & 0xff, i
);
1273 n
= (struct listaddr
*)malloc(sizeof(struct listaddr
));
1275 dolog(LOG_ERR
, 0, "ran out of memory"); /* fatal */
1280 n
->al_genid
= has_genid
? genid
: 0;
1286 n
->al_flags
= has_genid
? NBRF_GENID
: 0;
1287 n
->al_next
= v
->uv_neighbors
;
1288 v
->uv_neighbors
= n
;
1291 * If we are not configured to peer with non-pruning routers,
1292 * check the deprecated "I-know-how-to-prune" bit. This bit
1293 * was MBZ in early mrouted implementations (<3.5) and is required
1294 * to be set by the DVMRPv3 specification.
1296 if (!(v
->uv_flags
& VIFF_ALLOW_NONPRUNERS
) &&
1297 !((level
& 0x020000) || (pv
== 3 && mv
< 5))) {
1298 n
->al_flags
|= NBRF_TOOOLD
;
1302 * If this router implements the DVMRPv3 spec, then don't peer
1303 * with him if we haven't yet established a bidirectional connection.
1306 if (!in_router_list
) {
1307 IF_DEBUG(DEBUG_PEER
)
1308 dolog(LOG_DEBUG
, 0, "waiting for probe from %s with my addr",
1309 inet_fmt(addr
, s1
));
1310 n
->al_flags
|= NBRF_WAITING
;
1315 if (n
->al_flags
& NBRF_DONTPEER
) {
1316 IF_DEBUG(DEBUG_PEER
)
1317 dolog(LOG_DEBUG
, 0, "not peering with %s on vif %d because %x",
1318 inet_fmt(addr
, s1
), vifi
, n
->al_flags
& NBRF_DONTPEER
);
1323 * If we thought that we had no neighbors on this vif, send a route
1324 * report to the vif. If this is just a new neighbor on the same
1325 * vif, send the route report just to the new neighbor.
1327 if (NBRM_ISEMPTY(v
->uv_nbrmap
)) {
1328 send_tables
= v
->uv_dst_addr
;
1329 vifs_with_neighbors
++;
1335 NBRM_SET(i
, v
->uv_nbrmap
);
1336 add_neighbor_to_routes(vifi
, i
);
1339 * Found it. Reset its timer.
1343 if (n
->al_flags
& NBRF_WAITING
&& msgtype
== DVMRP_PROBE
) {
1344 n
->al_flags
&= ~NBRF_WAITING
;
1345 if (!in_router_list
) {
1346 dolog(LOG_WARNING
, 0, "possible one-way peering with %s on vif %d",
1347 inet_fmt(addr
, s1
), vifi
);
1348 n
->al_flags
|= NBRF_ONEWAY
;
1351 if (NBRM_ISEMPTY(v
->uv_nbrmap
)) {
1352 send_tables
= v
->uv_dst_addr
;
1353 vifs_with_neighbors
++;
1357 NBRM_SET(n
->al_index
, v
->uv_nbrmap
);
1358 add_neighbor_to_routes(vifi
, n
->al_index
);
1359 IF_DEBUG(DEBUG_PEER
)
1360 dolog(LOG_DEBUG
, 0, "%s on vif %d exits WAITING",
1361 inet_fmt(addr
, s1
), vifi
);
1365 if (n
->al_flags
& NBRF_ONEWAY
&& msgtype
== DVMRP_PROBE
) {
1366 if (in_router_list
) {
1367 if (NBRM_ISEMPTY(v
->uv_nbrmap
))
1368 vifs_with_neighbors
++;
1369 NBRM_SET(n
->al_index
, v
->uv_nbrmap
);
1370 add_neighbor_to_routes(vifi
, n
->al_index
);
1371 dolog(LOG_NOTICE
, 0, "peering with %s on vif %d is no longer one-way",
1372 inet_fmt(addr
, s1
), vifi
);
1373 n
->al_flags
&= ~NBRF_ONEWAY
;
1375 /* XXX rate-limited warning message? */
1376 IF_DEBUG(DEBUG_PEER
)
1377 dolog(LOG_DEBUG
, 0, "%s on vif %d is still ONEWAY",
1378 inet_fmt(addr
, s1
), vifi
);
1383 * When peering with a genid-capable but pre-DVMRP spec peer,
1384 * we might bring up the peering with a route report and not
1385 * remember his genid. Assume that he doesn't send a route
1386 * report and then reboot before sending a probe.
1388 if (has_genid
&& !(n
->al_flags
& NBRF_GENID
)) {
1389 n
->al_flags
|= NBRF_GENID
;
1390 n
->al_genid
= genid
;
1394 * update the neighbors version and protocol number and genid
1395 * if changed => router went down and came up,
1396 * so take action immediately.
1398 if ((n
->al_pv
!= pv
) ||
1400 (has_genid
&& n
->al_genid
!= genid
)) {
1403 IF_DEBUG(DEBUG_PEER
)
1405 "version/genid change neighbor %s [old:%d.%d/%8x, new:%d.%d/%8x]",
1407 n
->al_pv
, n
->al_mv
, n
->al_genid
, pv
, mv
, genid
);
1411 n
->al_genid
= genid
;
1415 if ((pv
== 3 && mv
> 2) || (pv
> 3 && pv
< 10)) {
1416 if (!(n
->al_flags
& VIFF_ONEWAY
) && has_genid
&& !in_router_list
&&
1417 (time(NULL
) - n
->al_ctime
> 20)) {
1418 if (NBRM_ISSET(n
->al_index
, v
->uv_nbrmap
)) {
1419 NBRM_CLR(n
->al_index
, v
->uv_nbrmap
);
1420 if (NBRM_ISEMPTY(v
->uv_nbrmap
))
1421 vifs_with_neighbors
--;
1423 delete_neighbor_from_routes(addr
, vifi
, n
->al_index
);
1424 reset_neighbor_state(vifi
, addr
);
1425 dolog(LOG_WARNING
, 0, "peering with %s on vif %d is one-way",
1426 inet_fmt(addr
, s1
), vifi
);
1427 n
->al_flags
|= NBRF_ONEWAY
;
1431 if (n
->al_flags
& NBRF_DONTPEER
) {
1432 IF_DEBUG(DEBUG_PEER
)
1433 dolog(LOG_DEBUG
, 0, "not peering with %s on vif %d because %x",
1434 inet_fmt(addr
, s1
), vifi
, n
->al_flags
& NBRF_DONTPEER
);
1438 /* check "leaf" flag */
1441 reset_neighbor_state(vifi
, addr
);
1446 send_probe_on_vif(v
);
1447 report(ALL_ROUTES
, vifi
, send_tables
);
1449 v
->uv_leaf_timer
= 0;
1450 v
->uv_flags
&= ~VIFF_LEAF
;
1457 * On every timer interrupt, advance the timer in each neighbor and
1458 * group entry on every vif.
1465 struct listaddr
*a
, *prev_a
;
1468 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; ++vifi
, ++v
) {
1469 if (v
->uv_leaf_timer
&& (v
->uv_leaf_timer
-= TIMER_INTERVAL
== 0)) {
1470 v
->uv_flags
|= VIFF_LEAF
;
1473 for (prev_a
= (struct listaddr
*)&(v
->uv_neighbors
),
1474 a
= v
->uv_neighbors
;
1476 prev_a
= a
, a
= a
->al_next
) {
1480 if (((a
->al_pv
== 3) && (a
->al_mv
>= 3)) ||
1481 ((a
->al_pv
> 3) && (a
->al_pv
< 10)))
1482 exp_time
= NEIGHBOR_EXPIRE_TIME
;
1484 exp_time
= OLD_NEIGHBOR_EXPIRE_TIME
;
1486 if ((a
->al_timer
+= TIMER_INTERVAL
) < exp_time
)
1489 IF_DEBUG(DEBUG_PEER
)
1490 dolog(LOG_DEBUG
, 0, "Neighbor %s (%d.%d) expired after %d seconds",
1491 inet_fmt(a
->al_addr
, s1
), a
->al_pv
, a
->al_mv
, exp_time
);
1494 * Neighbor has expired; delete it from the neighbor list,
1495 * delete it from the 'dominants' and 'subordinates arrays of
1496 * any route entries.
1498 NBRM_CLR(a
->al_index
, v
->uv_nbrmap
);
1499 nbrs
[a
->al_index
] = NULL
; /* XXX is it a good idea to reuse indxs? */
1502 prev_a
->al_next
= a
->al_next
;
1504 a
= prev_a
;/*XXX use ** */
1506 delete_neighbor_from_routes(addr
, vifi
, idx
);
1507 reset_neighbor_state(vifi
, addr
);
1509 if (NBRM_ISEMPTY(v
->uv_nbrmap
))
1510 vifs_with_neighbors
--;
1512 v
->uv_leaf_timer
= LEAF_CONFIRMATION_TIME
;
1515 if (v
->uv_querier
&&
1516 (v
->uv_querier
->al_timer
+= TIMER_INTERVAL
) >
1517 IGMP_OTHER_QUERIER_PRESENT_INTERVAL
) {
1519 * The current querier has timed out. We must become the
1522 IF_DEBUG(DEBUG_IGMP
)
1523 dolog(LOG_DEBUG
, 0, "querier %s timed out",
1524 inet_fmt(v
->uv_querier
->al_addr
, s1
));
1525 free(v
->uv_querier
);
1526 v
->uv_querier
= NULL
;
1527 v
->uv_flags
|= VIFF_QUERIER
;
1534 * Returns the neighbor info struct for a given neighbor
1537 neighbor_info(vifi_t vifi
, u_int32 addr
)
1541 for (u
= uvifs
[vifi
].uv_neighbors
; u
; u
= u
->al_next
)
1542 if (u
->al_addr
== addr
)
1548 static struct vnflags
{
1552 { VIFF_DOWN
, "down" },
1553 { VIFF_DISABLED
, "disabled" },
1554 { VIFF_QUERIER
, "querier" },
1555 { VIFF_ONEWAY
, "one-way" },
1556 { VIFF_LEAF
, "leaf" },
1557 { VIFF_IGMPV1
, "IGMPv1" },
1558 { VIFF_REXMIT_PRUNES
, "rexmit_prunes" },
1559 { VIFF_PASSIVE
, "passive" },
1560 { VIFF_ALLOW_NONPRUNERS
,"allow_nonpruners" },
1561 { VIFF_NOFLOOD
, "noflood" },
1562 { VIFF_NOTRANSIT
, "notransit" },
1563 { VIFF_BLASTER
, "blaster" },
1564 { VIFF_FORCE_LEAF
, "force_leaf" },
1565 { VIFF_OTUNNEL
, "old-tunnel" },
1568 static struct vnflags nbrflags
[] = {
1569 { NBRF_LEAF
, "leaf" },
1570 { NBRF_GENID
, "have-genid" },
1571 { NBRF_WAITING
, "waiting" },
1572 { NBRF_ONEWAY
, "one-way" },
1573 { NBRF_TOOOLD
, "too old" },
1574 { NBRF_TOOMANYROUTES
, "too many routes" },
1575 { NBRF_NOTPRUNING
, "not pruning?" },
1579 * Print the contents of the uvifs array on file 'fp'.
1588 struct vif_acl
*acl
;
1590 struct sioc_vif_req v_req
;
1595 fprintf(fp
, "vifs_with_neighbors = %d\n", vifs_with_neighbors
);
1597 if (vifs_with_neighbors
== 1)
1598 fprintf(fp
,"[This host is a leaf]\n\n");
1601 "\nVirtual Interface Table\n%s",
1602 "Vif Name Local-Address ");
1604 "M Thr Rate Flags\n");
1606 for (vifi
= 0, v
= uvifs
; vifi
< numvifs
; vifi
++, v
++) {
1608 fprintf(fp
, "%2u %6s %-15s %6s: %-18s %2u %3u %5u ",
1611 inet_fmt(v
->uv_lcl_addr
, s1
),
1612 (v
->uv_flags
& VIFF_TUNNEL
) ?
1615 (v
->uv_flags
& VIFF_TUNNEL
) ?
1616 inet_fmt(v
->uv_rmt_addr
, s2
) :
1617 inet_fmts(v
->uv_subnet
, v
->uv_subnetmask
, s3
),
1622 for (i
= 0; i
< sizeof(vifflags
) / sizeof(struct vnflags
); i
++)
1623 if (v
->uv_flags
& vifflags
[i
].vn_flag
)
1624 fprintf(fp
, " %s", vifflags
[i
].vn_name
);
1628 fprintf(fp, " #routes: %d\n", v->uv_nroutes);
1630 if (v
->uv_admetric
!= 0)
1631 fprintf(fp
, " advert-metric %2u\n",
1634 label
= "alternate subnets:";
1635 for (p
= v
->uv_addrs
; p
; p
= p
->pa_next
) {
1636 fprintf(fp
, " %18s %s\n", label
,
1637 inet_fmts(p
->pa_subnet
, p
->pa_subnetmask
, s1
));
1642 for (a
= v
->uv_neighbors
; a
!= NULL
; a
= a
->al_next
) {
1643 fprintf(fp
, " %6s %s (%d.%d) [%d]",
1644 label
, inet_fmt(a
->al_addr
, s1
), a
->al_pv
, a
->al_mv
,
1646 for (i
= 0; i
< sizeof(nbrflags
) / sizeof(struct vnflags
); i
++)
1647 if (a
->al_flags
& nbrflags
[i
].vn_flag
)
1648 fprintf(fp
, " %s", nbrflags
[i
].vn_name
);
1649 fprintf(fp
, " up %s\n", scaletime(now
- a
->al_ctime
));
1650 /*fprintf(fp, " #routes %d\n", a->al_nroutes);*/
1654 label
= "group host (time left):";
1655 for (a
= v
->uv_groups
; a
!= NULL
; a
= a
->al_next
) {
1656 fprintf(fp
, " %23s %-15s %-15s (%s)\n",
1658 inet_fmt(a
->al_addr
, s1
),
1659 inet_fmt(a
->al_reporter
, s2
),
1660 scaletime(timer_leftTimer(a
->al_timerid
)));
1663 label
= "boundaries:";
1664 for (acl
= v
->uv_acl
; acl
!= NULL
; acl
= acl
->acl_next
) {
1665 fprintf(fp
, " %11s %-18s\n", label
,
1666 inet_fmts(acl
->acl_addr
, acl
->acl_mask
, s1
));
1670 struct vf_element
*vfe
;
1673 sprintf(lbuf
, "%5s %7s filter:",
1674 v
->uv_filter
->vf_flags
& VFF_BIDIR
? "bidir"
1676 v
->uv_filter
->vf_type
== VFT_ACCEPT
? "accept"
1679 for (vfe
= v
->uv_filter
->vf_filter
;
1680 vfe
!= NULL
; vfe
= vfe
->vfe_next
) {
1681 fprintf(fp
, " %23s %-18s%s\n",
1683 inet_fmts(vfe
->vfe_addr
, vfe
->vfe_mask
, s1
),
1684 vfe
->vfe_flags
& VFEF_EXACT
? " (exact)" : "");
1688 if (!(v
->uv_flags
& (VIFF_TUNNEL
|VIFF_DOWN
|VIFF_DISABLED
))) {
1689 fprintf(fp
, " IGMP querier: ");
1690 if (v
->uv_querier
== NULL
)
1691 if (v
->uv_flags
& VIFF_QUERIER
)
1692 fprintf(fp
, "%-18s (this system)\n",
1693 inet_fmt(v
->uv_lcl_addr
, s1
));
1695 fprintf(fp
, "NONE - querier election failure?\n");
1697 fprintf(fp
, "%-18s up %s last heard %s ago\n",
1698 inet_fmt(v
->uv_querier
->al_addr
, s1
),
1699 scaletime(now
- v
->uv_querier
->al_ctime
),
1700 scaletime(v
->uv_querier
->al_timer
));
1702 if (v
->uv_flags
& VIFF_BLASTER
)
1703 fprintf(fp
, " blasterbuf size: %dk\n",
1704 v
->uv_blasterlen
/ 1024);
1705 fprintf(fp
, " Nbr bitmaps: 0x%08lx%08lx\n",/*XXX*/
1706 v
->uv_nbrmap
.hi
, v
->uv_nbrmap
.lo
);
1707 if (v
->uv_prune_lifetime
!= 0)
1708 fprintf(fp
, " Prune Lifetime: %d seconds\n",
1709 v
->uv_prune_lifetime
);
1712 if (did_final_init
) {
1713 if (ioctl(udp_socket
, SIOCGETVIFCNT
, (char *)&v_req
) < 0) {
1714 dolog(LOG_WARNING
, errno
,
1715 "SIOCGETVIFCNT fails on vif %d", vifi
);
1717 fprintf(fp
, " pkts/bytes in : %lu/%lu\n",
1718 v_req
.icount
, v_req
.ibytes
);
1719 fprintf(fp
, " pkts/bytes out: %lu/%lu\n",
1720 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
);