]>
Commit | Line | Data |
---|---|---|
12e41d03 | 1 | /* |
896014f4 DL |
2 | * PIM for Quagga |
3 | * Copyright (C) 2008 Everton da Silva Marques | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation; either version 2 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License along | |
16 | * with this program; see the file COPYING; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | */ | |
12e41d03 DL |
19 | |
20 | #include <zebra.h> | |
21 | #include "log.h" | |
22 | #include "privs.h" | |
744d91b3 | 23 | #include "if.h" |
065bee4b | 24 | #include "prefix.h" |
dfe43e25 DW |
25 | #include "vty.h" |
26 | #include "plist.h" | |
fe232c19 | 27 | #include "sockopt.h" |
12e41d03 DL |
28 | |
29 | #include "pimd.h" | |
8e38a2cf | 30 | #include "pim_rpf.h" |
12e41d03 | 31 | #include "pim_mroute.h" |
37653d4f | 32 | #include "pim_oil.h" |
12e41d03 DL |
33 | #include "pim_str.h" |
34 | #include "pim_time.h" | |
35 | #include "pim_iface.h" | |
36 | #include "pim_macro.h" | |
c8ae3ce8 | 37 | #include "pim_rp.h" |
59471fb8 | 38 | #include "pim_oil.h" |
998af219 | 39 | #include "pim_register.h" |
56638739 | 40 | #include "pim_ifchannel.h" |
e3be0432 | 41 | #include "pim_zlookup.h" |
15a5dafe | 42 | #include "pim_ssm.h" |
2002dcdb | 43 | #include "pim_sock.h" |
12e41d03 | 44 | |
8ea5d944 | 45 | static void mroute_read_on(struct pim_instance *pim); |
12e41d03 | 46 | |
cdbfaec5 | 47 | static int pim_mroute_set(struct pim_instance *pim, int enable) |
12e41d03 | 48 | { |
d62a17ae | 49 | int err; |
f507c196 | 50 | int opt; |
d62a17ae | 51 | socklen_t opt_len = sizeof(opt); |
d62a17ae | 52 | long flags; |
53 | ||
cdbfaec5 DS |
54 | /* |
55 | * We need to create the VRF table for the pim mroute_socket | |
56 | */ | |
57 | if (pim->vrf_id != VRF_DEFAULT) { | |
f507c196 DS |
58 | if (pimd_privs.change(ZPRIVS_RAISE)) |
59 | zlog_err( | |
60 | "pim_mroute_socket_enable: could not raise privs, %s", | |
61 | safe_strerror(errno)); | |
62 | ||
44a1bd88 | 63 | opt = pim->vrf->data.l.table_id; |
cdbfaec5 DS |
64 | err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_TABLE, |
65 | &opt, opt_len); | |
66 | if (err) { | |
67 | zlog_warn( | |
68 | "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP, MRT_TABLE=%d): errno=%d: %s", | |
69 | __FILE__, __PRETTY_FUNCTION__, | |
70 | pim->mroute_socket, opt, errno, | |
71 | safe_strerror(errno)); | |
72 | return -1; | |
73 | } | |
f507c196 DS |
74 | |
75 | if (pimd_privs.change(ZPRIVS_LOWER)) | |
76 | zlog_err( | |
77 | "pim_mroute_socket_enable: could not lower privs, %s", | |
78 | safe_strerror(errno)); | |
79 | } | |
80 | ||
81 | opt = enable ? MRT_INIT : MRT_DONE; | |
82 | err = setsockopt(pim->mroute_socket, IPPROTO_IP, opt, &opt, opt_len); | |
83 | if (err) { | |
84 | zlog_warn( | |
85 | "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,%s=%d): errno=%d: %s", | |
86 | __FILE__, __PRETTY_FUNCTION__, pim->mroute_socket, | |
87 | enable ? "MRT_INIT" : "MRT_DONE", opt, errno, | |
88 | safe_strerror(errno)); | |
89 | return -1; | |
cdbfaec5 DS |
90 | } |
91 | ||
466e4e5b DS |
92 | #if defined(HAVE_IP_PKTINFO) |
93 | if (enable) { | |
94 | /* Linux and Solaris IP_PKTINFO */ | |
95 | opt = 1; | |
96 | if (setsockopt(pim->mroute_socket, IPPROTO_IP, IP_PKTINFO, &opt, | |
97 | sizeof(opt))) { | |
98 | zlog_warn( | |
99 | "Could not set IP_PKTINFO on socket fd=%d: errno=%d: %s", | |
100 | pim->mroute_socket, errno, | |
101 | safe_strerror(errno)); | |
102 | } | |
103 | } | |
104 | #endif | |
105 | ||
cdbfaec5 | 106 | setsockopt_so_recvbuf(pim->mroute_socket, 1024 * 1024 * 8); |
d62a17ae | 107 | |
cdbfaec5 | 108 | flags = fcntl(pim->mroute_socket, F_GETFL, 0); |
d62a17ae | 109 | if (flags < 0) { |
cdbfaec5 DS |
110 | zlog_warn("Could not get flags on socket fd:%d %d %s", |
111 | pim->mroute_socket, errno, safe_strerror(errno)); | |
112 | close(pim->mroute_socket); | |
d62a17ae | 113 | return -1; |
114 | } | |
cdbfaec5 DS |
115 | if (fcntl(pim->mroute_socket, F_SETFL, flags | O_NONBLOCK)) { |
116 | zlog_warn("Could not set O_NONBLOCK on socket fd:%d %d %s", | |
117 | pim->mroute_socket, errno, safe_strerror(errno)); | |
118 | close(pim->mroute_socket); | |
d62a17ae | 119 | return -1; |
120 | } | |
121 | ||
122 | if (enable) { | |
77b7d90b | 123 | #if defined linux |
d62a17ae | 124 | int upcalls = IGMPMSG_WRVIFWHOLE; |
125 | opt = MRT_PIM; | |
126 | ||
cdbfaec5 | 127 | err = setsockopt(pim->mroute_socket, IPPROTO_IP, opt, &upcalls, |
d62a17ae | 128 | sizeof(upcalls)); |
129 | if (err) { | |
130 | zlog_warn( | |
131 | "Failure to register for VIFWHOLE and WRONGVIF upcalls %d %s", | |
132 | errno, safe_strerror(errno)); | |
133 | return -1; | |
134 | } | |
77b7d90b | 135 | #else |
d62a17ae | 136 | zlog_warn( |
137 | "PIM-SM will not work properly on this platform, until the ability to receive the WRVIFWHOLE upcall"); | |
77b7d90b | 138 | #endif |
d62a17ae | 139 | } |
140 | ||
141 | return 0; | |
12e41d03 DL |
142 | } |
143 | ||
08e1fe76 | 144 | static const char *igmpmsgtype2str[IGMPMSG_WRVIFWHOLE + 1] = { |
d62a17ae | 145 | "<unknown_upcall?>", "NOCACHE", "WRONGVIF", "WHOLEPKT", "WRVIFWHOLE"}; |
146 | ||
147 | static int pim_mroute_msg_nocache(int fd, struct interface *ifp, | |
148 | const struct igmpmsg *msg) | |
12e41d03 | 149 | { |
d62a17ae | 150 | struct pim_interface *pim_ifp = ifp->info; |
151 | struct pim_upstream *up; | |
152 | struct pim_rpf *rpg; | |
153 | struct prefix_sg sg; | |
154 | ||
fec883d9 | 155 | rpg = RP(pim_ifp->pim, msg->im_dst); |
d62a17ae | 156 | /* |
157 | * If the incoming interface is unknown OR | |
158 | * the Interface type is SSM we don't need to | |
159 | * do anything here | |
160 | */ | |
161 | if ((pim_rpf_addr_is_inaddr_none(rpg)) || (!pim_ifp) | |
162 | || (!(PIM_I_am_DR(pim_ifp)))) { | |
163 | if (PIM_DEBUG_MROUTE_DETAIL) | |
164 | zlog_debug( | |
165 | "%s: Interface is not configured correctly to handle incoming packet: Could be !DR, !pim_ifp, !SM, !RP", | |
166 | __PRETTY_FUNCTION__); | |
167 | return 0; | |
168 | } | |
04b40f02 | 169 | |
d62a17ae | 170 | /* |
171 | * If we've received a multicast packet that isn't connected to | |
172 | * us | |
173 | */ | |
174 | if (!pim_if_connected_to_source(ifp, msg->im_src)) { | |
175 | if (PIM_DEBUG_MROUTE_DETAIL) | |
176 | zlog_debug( | |
177 | "%s: Received incoming packet that doesn't originate on our seg", | |
178 | __PRETTY_FUNCTION__); | |
179 | return 0; | |
180 | } | |
065bee4b | 181 | |
d62a17ae | 182 | memset(&sg, 0, sizeof(struct prefix_sg)); |
183 | sg.src = msg->im_src; | |
184 | sg.grp = msg->im_dst; | |
185 | ||
186 | up = pim_upstream_find_or_add(&sg, ifp, PIM_UPSTREAM_FLAG_MASK_FHR, | |
187 | __PRETTY_FUNCTION__); | |
188 | if (!up) { | |
189 | if (PIM_DEBUG_MROUTE) { | |
190 | zlog_debug( | |
191 | "%s: Failure to add upstream information for %s", | |
192 | __PRETTY_FUNCTION__, pim_str_sg_dump(&sg)); | |
193 | } | |
194 | return 0; | |
195 | } | |
c29a5806 | 196 | |
d62a17ae | 197 | /* |
198 | * I moved this debug till after the actual add because | |
199 | * I want to take advantage of the up->sg_str being filled in. | |
200 | */ | |
201 | if (PIM_DEBUG_MROUTE) { | |
202 | zlog_debug("%s: Adding a Route %s for WHOLEPKT consumption", | |
203 | __PRETTY_FUNCTION__, up->sg_str); | |
204 | } | |
8bfb8b67 | 205 | |
d62a17ae | 206 | PIM_UPSTREAM_FLAG_SET_SRC_STREAM(up->flags); |
19b807ca | 207 | pim_upstream_keep_alive_timer_start(up, pim_ifp->pim->keep_alive_time); |
d62a17ae | 208 | |
209 | up->channel_oil->cc.pktcnt++; | |
210 | PIM_UPSTREAM_FLAG_SET_FHR(up->flags); | |
211 | // resolve mfcc_parent prior to mroute_add in channel_add_oif | |
212 | if (up->channel_oil->oil.mfcc_parent >= MAXVIFS) { | |
213 | int vif_index = 0; | |
214 | vif_index = pim_if_find_vifindex_by_ifindex( | |
7cfc7bcf | 215 | pim_ifp->pim, |
d62a17ae | 216 | up->rpf.source_nexthop.interface->ifindex); |
217 | up->channel_oil->oil.mfcc_parent = vif_index; | |
218 | } | |
219 | pim_register_join(up); | |
59471fb8 | 220 | |
d62a17ae | 221 | return 0; |
e355e30f | 222 | } |
12e41d03 | 223 | |
d62a17ae | 224 | static int pim_mroute_msg_wholepkt(int fd, struct interface *ifp, |
225 | const char *buf) | |
e355e30f | 226 | { |
d62a17ae | 227 | struct pim_interface *pim_ifp; |
228 | struct prefix_sg sg; | |
229 | struct pim_rpf *rpg; | |
230 | const struct ip *ip_hdr; | |
231 | struct pim_upstream *up; | |
232 | ||
9b29ea95 DS |
233 | pim_ifp = ifp->info; |
234 | ||
d62a17ae | 235 | ip_hdr = (const struct ip *)buf; |
236 | ||
237 | memset(&sg, 0, sizeof(struct prefix_sg)); | |
238 | sg.src = ip_hdr->ip_src; | |
239 | sg.grp = ip_hdr->ip_dst; | |
240 | ||
9b29ea95 | 241 | up = pim_upstream_find(pim_ifp->pim, &sg); |
d62a17ae | 242 | if (!up) { |
243 | struct prefix_sg star = sg; | |
244 | star.src.s_addr = INADDR_ANY; | |
245 | ||
9b29ea95 | 246 | up = pim_upstream_find(pim_ifp->pim, &star); |
d62a17ae | 247 | |
248 | if (up && PIM_UPSTREAM_FLAG_TEST_SRC_IGMP(up->flags)) { | |
2002dcdb | 249 | up = pim_upstream_add(pim_ifp->pim, &sg, ifp, |
d62a17ae | 250 | PIM_UPSTREAM_FLAG_MASK_SRC_LHR, |
0885a9f1 | 251 | __PRETTY_FUNCTION__, NULL); |
d62a17ae | 252 | if (!up) { |
253 | if (PIM_DEBUG_MROUTE) | |
254 | zlog_debug( | |
255 | "%s: Unable to create upstream information for %s", | |
256 | __PRETTY_FUNCTION__, | |
257 | pim_str_sg_dump(&sg)); | |
258 | return 0; | |
259 | } | |
260 | pim_upstream_keep_alive_timer_start( | |
19b807ca | 261 | up, pim_ifp->pim->keep_alive_time); |
9b29ea95 | 262 | pim_upstream_inherited_olist(pim_ifp->pim, up); |
1eca8576 DS |
263 | pim_upstream_switch(pim_ifp->pim, up, |
264 | PIM_UPSTREAM_JOINED); | |
d62a17ae | 265 | |
266 | if (PIM_DEBUG_MROUTE) | |
267 | zlog_debug("%s: Creating %s upstream on LHR", | |
268 | __PRETTY_FUNCTION__, up->sg_str); | |
269 | return 0; | |
270 | } | |
271 | if (PIM_DEBUG_MROUTE_DETAIL) { | |
272 | zlog_debug( | |
273 | "%s: Unable to find upstream channel WHOLEPKT%s", | |
274 | __PRETTY_FUNCTION__, pim_str_sg_dump(&sg)); | |
275 | } | |
276 | return 0; | |
277 | } | |
59471fb8 | 278 | |
d62a17ae | 279 | pim_ifp = up->rpf.source_nexthop.interface->info; |
998af219 | 280 | |
fec883d9 | 281 | rpg = RP(pim_ifp->pim, sg.grp); |
c8ae3ce8 | 282 | |
d62a17ae | 283 | if ((pim_rpf_addr_is_inaddr_none(rpg)) || (!pim_ifp) |
284 | || (!(PIM_I_am_DR(pim_ifp)))) { | |
285 | if (PIM_DEBUG_MROUTE) { | |
286 | zlog_debug("%s: Failed Check send packet", | |
287 | __PRETTY_FUNCTION__); | |
288 | } | |
289 | return 0; | |
290 | } | |
84366c7e | 291 | |
d62a17ae | 292 | /* |
293 | * If we've received a register suppress | |
294 | */ | |
295 | if (!up->t_rs_timer) { | |
6f439a70 | 296 | if (pim_is_grp_ssm(pim_ifp->pim, sg.grp)) { |
d62a17ae | 297 | if (PIM_DEBUG_PIM_REG) |
298 | zlog_debug( | |
299 | "%s register forward skipped as group is SSM", | |
300 | pim_str_sg_dump(&sg)); | |
301 | return 0; | |
302 | } | |
303 | pim_register_send((uint8_t *)buf + sizeof(struct ip), | |
304 | ntohs(ip_hdr->ip_len) - sizeof(struct ip), | |
305 | pim_ifp->primary_address, rpg, 0, up); | |
306 | } | |
307 | return 0; | |
e355e30f | 308 | } |
12e41d03 | 309 | |
d62a17ae | 310 | static int pim_mroute_msg_wrongvif(int fd, struct interface *ifp, |
311 | const struct igmpmsg *msg) | |
e355e30f | 312 | { |
d62a17ae | 313 | struct pim_ifchannel *ch; |
314 | struct pim_interface *pim_ifp; | |
315 | struct prefix_sg sg; | |
316 | ||
317 | memset(&sg, 0, sizeof(struct prefix_sg)); | |
318 | sg.src = msg->im_src; | |
319 | sg.grp = msg->im_dst; | |
320 | ||
321 | /* | |
322 | Send Assert(S,G) on iif as response to WRONGVIF kernel upcall. | |
323 | ||
324 | RFC 4601 4.8.2. PIM-SSM-Only Routers | |
325 | ||
326 | iif is the incoming interface of the packet. | |
327 | if (iif is in inherited_olist(S,G)) { | |
328 | send Assert(S,G) on iif | |
329 | } | |
330 | */ | |
331 | ||
332 | if (!ifp) { | |
333 | if (PIM_DEBUG_MROUTE) | |
334 | zlog_debug( | |
335 | "%s: WRONGVIF (S,G)=%s could not find input interface for input_vif_index=%d", | |
336 | __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), | |
337 | msg->im_vif); | |
338 | return -1; | |
339 | } | |
12e41d03 | 340 | |
d62a17ae | 341 | pim_ifp = ifp->info; |
342 | if (!pim_ifp) { | |
343 | if (PIM_DEBUG_MROUTE) | |
344 | zlog_debug( | |
345 | "%s: WRONGVIF (S,G)=%s multicast not enabled on interface %s", | |
346 | __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), | |
347 | ifp->name); | |
348 | return -2; | |
349 | } | |
c29a5806 | 350 | |
d62a17ae | 351 | ch = pim_ifchannel_find(ifp, &sg); |
352 | if (!ch) { | |
353 | struct prefix_sg star_g = sg; | |
354 | if (PIM_DEBUG_MROUTE) | |
355 | zlog_debug( | |
356 | "%s: WRONGVIF (S,G)=%s could not find channel on interface %s", | |
357 | __PRETTY_FUNCTION__, pim_str_sg_dump(&sg), | |
358 | ifp->name); | |
359 | ||
360 | star_g.src.s_addr = INADDR_ANY; | |
361 | ch = pim_ifchannel_find(ifp, &star_g); | |
362 | if (!ch) { | |
363 | if (PIM_DEBUG_MROUTE) | |
364 | zlog_debug( | |
365 | "%s: WRONGVIF (*,G)=%s could not find channel on interface %s", | |
366 | __PRETTY_FUNCTION__, | |
367 | pim_str_sg_dump(&star_g), ifp->name); | |
368 | return -3; | |
369 | } | |
370 | } | |
12e41d03 | 371 | |
d62a17ae | 372 | /* |
373 | RFC 4601: 4.6.1. (S,G) Assert Message State Machine | |
374 | ||
375 | Transitions from NoInfo State | |
376 | ||
377 | An (S,G) data packet arrives on interface I, AND | |
378 | CouldAssert(S,G,I)==TRUE An (S,G) data packet arrived on an | |
379 | downstream interface that is in our (S,G) outgoing interface | |
380 | list. We optimistically assume that we will be the assert | |
381 | winner for this (S,G), and so we transition to the "I am Assert | |
382 | Winner" state and perform Actions A1 (below), which will | |
383 | initiate the assert negotiation for (S,G). | |
384 | */ | |
385 | ||
386 | if (ch->ifassert_state != PIM_IFASSERT_NOINFO) { | |
387 | if (PIM_DEBUG_MROUTE) { | |
388 | zlog_debug( | |
389 | "%s: WRONGVIF (S,G)=%s channel is not on Assert NoInfo state for interface %s", | |
390 | __PRETTY_FUNCTION__, ch->sg_str, ifp->name); | |
391 | } | |
392 | return -4; | |
393 | } | |
e355e30f | 394 | |
d62a17ae | 395 | if (!PIM_IF_FLAG_TEST_COULD_ASSERT(ch->flags)) { |
396 | if (PIM_DEBUG_MROUTE) { | |
397 | zlog_debug( | |
398 | "%s: WRONGVIF (S,G)=%s interface %s is not downstream for channel", | |
399 | __PRETTY_FUNCTION__, ch->sg_str, ifp->name); | |
400 | } | |
401 | return -5; | |
402 | } | |
403 | ||
404 | if (assert_action_a1(ch)) { | |
405 | if (PIM_DEBUG_MROUTE) { | |
406 | zlog_debug( | |
407 | "%s: WRONGVIF (S,G)=%s assert_action_a1 failure on interface %s", | |
408 | __PRETTY_FUNCTION__, ch->sg_str, ifp->name); | |
409 | } | |
410 | return -6; | |
411 | } | |
e355e30f | 412 | |
d62a17ae | 413 | return 0; |
e355e30f DS |
414 | } |
415 | ||
d62a17ae | 416 | static int pim_mroute_msg_wrvifwhole(int fd, struct interface *ifp, |
417 | const char *buf) | |
08e1fe76 | 418 | { |
d62a17ae | 419 | const struct ip *ip_hdr = (const struct ip *)buf; |
420 | struct pim_interface *pim_ifp; | |
421 | struct pim_ifchannel *ch; | |
422 | struct pim_upstream *up; | |
423 | struct prefix_sg star_g; | |
424 | struct prefix_sg sg; | |
425 | struct channel_oil *oil; | |
426 | ||
fec883d9 DS |
427 | pim_ifp = ifp->info; |
428 | ||
d62a17ae | 429 | memset(&sg, 0, sizeof(struct prefix_sg)); |
430 | sg.src = ip_hdr->ip_src; | |
431 | sg.grp = ip_hdr->ip_dst; | |
432 | ||
433 | ch = pim_ifchannel_find(ifp, &sg); | |
434 | if (ch) { | |
435 | if (PIM_DEBUG_MROUTE) | |
436 | zlog_debug( | |
437 | "WRVIFWHOLE (S,G)=%s found ifchannel on interface %s", | |
438 | ch->sg_str, ifp->name); | |
439 | return -1; | |
440 | } | |
b7ddd2ec | 441 | |
d62a17ae | 442 | star_g = sg; |
443 | star_g.src.s_addr = INADDR_ANY; | |
b7ddd2ec | 444 | #if 0 |
0490c22d DS |
445 | ch = pim_ifchannel_find(ifp, &star_g); |
446 | if (ch) | |
447 | { | |
448 | if (PIM_DEBUG_MROUTE) | |
449 | zlog_debug ("WRVIFWHOLE (*,G)=%s found ifchannel on interface %s", | |
450 | pim_str_sg_dump (&star_g), ifp->name); | |
451 | return -1; | |
452 | } | |
5cd11e3c | 453 | #endif |
08e1fe76 | 454 | |
9b29ea95 | 455 | up = pim_upstream_find(pim_ifp->pim, &sg); |
d62a17ae | 456 | if (up) { |
457 | struct pim_upstream *parent; | |
458 | struct pim_nexthop source; | |
fec883d9 | 459 | struct pim_rpf *rpf = RP(pim_ifp->pim, sg.grp); |
d62a17ae | 460 | if (!rpf || !rpf->source_nexthop.interface) |
461 | return 0; | |
462 | ||
463 | /* | |
464 | * If we have received a WRVIFWHOLE and are at this | |
465 | * point, we could be receiving the packet on the *,G | |
466 | * tree, let's check and if so we can safely drop | |
467 | * it. | |
468 | */ | |
9b29ea95 | 469 | parent = pim_upstream_find(pim_ifp->pim, &star_g); |
d62a17ae | 470 | if (parent && parent->rpf.source_nexthop.interface == ifp) |
471 | return 0; | |
472 | ||
473 | pim_ifp = rpf->source_nexthop.interface->info; | |
474 | ||
475 | memset(&source, 0, sizeof(source)); | |
476 | /* | |
477 | * If we are the fhr that means we are getting a callback during | |
478 | * the pimreg period, so I believe we can ignore this packet | |
479 | */ | |
480 | if (!PIM_UPSTREAM_FLAG_TEST_FHR(up->flags)) { | |
481 | // No if channel, but upstream we are at the RP. | |
d9c9a9ee DS |
482 | if (pim_nexthop_lookup(pim_ifp->pim, &source, |
483 | up->upstream_register, 0) | |
df766618 | 484 | == 0) { |
d62a17ae | 485 | pim_register_stop_send(source.interface, &sg, |
486 | pim_ifp->primary_address, | |
487 | up->upstream_register); | |
df766618 DS |
488 | up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE; |
489 | } | |
d62a17ae | 490 | if (!up->channel_oil) |
491 | up->channel_oil = pim_channel_oil_add( | |
611925dc DS |
492 | pim_ifp->pim, &sg, |
493 | pim_ifp->mroute_vif_index); | |
9b29ea95 | 494 | pim_upstream_inherited_olist(pim_ifp->pim, up); |
d62a17ae | 495 | if (!up->channel_oil->installed) |
496 | pim_mroute_add(up->channel_oil, | |
497 | __PRETTY_FUNCTION__); | |
d62a17ae | 498 | } else { |
d9c9a9ee DS |
499 | if (I_am_RP(pim_ifp->pim, up->sg.grp)) { |
500 | if (pim_nexthop_lookup(pim_ifp->pim, &source, | |
d62a17ae | 501 | up->upstream_register, 0) |
502 | == 0) | |
503 | pim_register_stop_send( | |
504 | source.interface, &sg, | |
505 | pim_ifp->primary_address, | |
506 | up->upstream_register); | |
507 | up->sptbit = PIM_UPSTREAM_SPTBIT_TRUE; | |
508 | } | |
509 | pim_upstream_keep_alive_timer_start( | |
19b807ca | 510 | up, pim_ifp->pim->keep_alive_time); |
9b29ea95 | 511 | pim_upstream_inherited_olist(pim_ifp->pim, up); |
d62a17ae | 512 | pim_mroute_msg_wholepkt(fd, ifp, buf); |
513 | } | |
514 | return 0; | |
515 | } | |
8e38a2cf | 516 | |
d62a17ae | 517 | pim_ifp = ifp->info; |
611925dc | 518 | oil = pim_channel_oil_add(pim_ifp->pim, &sg, pim_ifp->mroute_vif_index); |
d62a17ae | 519 | if (!oil->installed) |
520 | pim_mroute_add(oil, __PRETTY_FUNCTION__); | |
521 | if (pim_if_connected_to_source(ifp, sg.src)) { | |
2002dcdb DS |
522 | up = pim_upstream_add(pim_ifp->pim, &sg, ifp, |
523 | PIM_UPSTREAM_FLAG_MASK_FHR, | |
0885a9f1 | 524 | __PRETTY_FUNCTION__, NULL); |
d62a17ae | 525 | if (!up) { |
526 | if (PIM_DEBUG_MROUTE) | |
527 | zlog_debug( | |
528 | "%s: WRONGVIF%s unable to create upstream on interface", | |
529 | pim_str_sg_dump(&sg), ifp->name); | |
530 | return -2; | |
531 | } | |
532 | PIM_UPSTREAM_FLAG_SET_SRC_STREAM(up->flags); | |
19b807ca | 533 | pim_upstream_keep_alive_timer_start(up, pim_ifp->pim->keep_alive_time); |
d62a17ae | 534 | up->channel_oil = oil; |
535 | up->channel_oil->cc.pktcnt++; | |
536 | pim_register_join(up); | |
9b29ea95 | 537 | pim_upstream_inherited_olist(pim_ifp->pim, up); |
d62a17ae | 538 | |
539 | // Send the packet to the RP | |
540 | pim_mroute_msg_wholepkt(fd, ifp, buf); | |
541 | } | |
08e1fe76 | 542 | |
d62a17ae | 543 | return 0; |
08e1fe76 DS |
544 | } |
545 | ||
405d6357 | 546 | static int pim_mroute_msg(struct pim_instance *pim, const char *buf, |
90450a3d | 547 | int buf_size, ifindex_t ifindex) |
e355e30f | 548 | { |
d62a17ae | 549 | struct interface *ifp; |
550 | struct pim_interface *pim_ifp; | |
551 | const struct ip *ip_hdr; | |
552 | const struct igmpmsg *msg; | |
553 | char ip_src_str[INET_ADDRSTRLEN] = ""; | |
554 | char ip_dst_str[INET_ADDRSTRLEN] = ""; | |
555 | char src_str[INET_ADDRSTRLEN] = "<src?>"; | |
556 | char grp_str[INET_ADDRSTRLEN] = "<grp?>"; | |
557 | struct in_addr ifaddr; | |
558 | struct igmp_sock *igmp; | |
559 | ||
560 | ip_hdr = (const struct ip *)buf; | |
561 | ||
562 | if (ip_hdr->ip_p == IPPROTO_IGMP) { | |
563 | ||
564 | /* We have the IP packet but we do not know which interface this | |
565 | * packet was | |
566 | * received on. Find the interface that is on the same subnet as | |
567 | * the source | |
568 | * of the IP packet. | |
569 | */ | |
90450a3d | 570 | ifp = if_lookup_by_index(ifindex, pim->vrf_id); |
d62a17ae | 571 | |
1ef8c24e | 572 | if (!ifp || !ifp->info) |
d62a17ae | 573 | return 0; |
90450a3d | 574 | |
d62a17ae | 575 | pim_ifp = ifp->info; |
576 | ifaddr = pim_find_primary_addr(ifp); | |
577 | igmp = pim_igmp_sock_lookup_ifaddr(pim_ifp->igmp_socket_list, | |
578 | ifaddr); | |
579 | ||
580 | if (PIM_DEBUG_MROUTE) { | |
581 | pim_inet4_dump("<src?>", ip_hdr->ip_src, ip_src_str, | |
582 | sizeof(ip_src_str)); | |
583 | pim_inet4_dump("<dst?>", ip_hdr->ip_dst, ip_dst_str, | |
584 | sizeof(ip_dst_str)); | |
585 | ||
586 | zlog_warn( | |
7c2bfc2a DS |
587 | "%s(%s): igmp kernel upcall on %s(%p) for %s -> %s", |
588 | __PRETTY_FUNCTION__, pim->vrf->name, ifp->name, | |
589 | igmp, ip_src_str, ip_dst_str); | |
d62a17ae | 590 | } |
591 | if (igmp) | |
592 | pim_igmp_packet(igmp, (char *)buf, buf_size); | |
593 | ||
594 | } else if (ip_hdr->ip_p) { | |
595 | if (PIM_DEBUG_MROUTE_DETAIL) { | |
596 | pim_inet4_dump("<src?>", ip_hdr->ip_src, src_str, | |
597 | sizeof(src_str)); | |
598 | pim_inet4_dump("<grp?>", ip_hdr->ip_dst, grp_str, | |
599 | sizeof(grp_str)); | |
600 | zlog_debug( | |
601 | "%s: no kernel upcall proto=%d src: %s dst: %s msg_size=%d", | |
602 | __PRETTY_FUNCTION__, ip_hdr->ip_p, src_str, | |
603 | grp_str, buf_size); | |
604 | } | |
605 | ||
606 | } else { | |
607 | msg = (const struct igmpmsg *)buf; | |
608 | ||
7cfc7bcf | 609 | ifp = pim_if_find_by_vif_index(pim, msg->im_vif); |
d62a17ae | 610 | |
611 | if (!ifp) | |
612 | return 0; | |
613 | if (PIM_DEBUG_MROUTE) { | |
614 | pim_inet4_dump("<src?>", msg->im_src, src_str, | |
615 | sizeof(src_str)); | |
616 | pim_inet4_dump("<grp?>", msg->im_dst, grp_str, | |
617 | sizeof(grp_str)); | |
618 | zlog_warn( | |
619 | "%s: pim kernel upcall %s type=%d ip_p=%d from fd=%d for (S,G)=(%s,%s) on %s vifi=%d size=%d", | |
620 | __PRETTY_FUNCTION__, | |
621 | igmpmsgtype2str[msg->im_msgtype], | |
405d6357 DS |
622 | msg->im_msgtype, ip_hdr->ip_p, |
623 | pim->mroute_socket, src_str, grp_str, ifp->name, | |
624 | msg->im_vif, buf_size); | |
d62a17ae | 625 | } |
626 | ||
627 | switch (msg->im_msgtype) { | |
628 | case IGMPMSG_WRONGVIF: | |
405d6357 DS |
629 | return pim_mroute_msg_wrongvif(pim->mroute_socket, ifp, |
630 | msg); | |
d62a17ae | 631 | break; |
632 | case IGMPMSG_NOCACHE: | |
405d6357 DS |
633 | return pim_mroute_msg_nocache(pim->mroute_socket, ifp, |
634 | msg); | |
d62a17ae | 635 | break; |
636 | case IGMPMSG_WHOLEPKT: | |
405d6357 | 637 | return pim_mroute_msg_wholepkt(pim->mroute_socket, ifp, |
d62a17ae | 638 | (const char *)msg); |
639 | break; | |
640 | case IGMPMSG_WRVIFWHOLE: | |
405d6357 DS |
641 | return pim_mroute_msg_wrvifwhole( |
642 | pim->mroute_socket, ifp, (const char *)msg); | |
d62a17ae | 643 | break; |
644 | default: | |
645 | break; | |
646 | } | |
647 | } | |
12e41d03 | 648 | |
d62a17ae | 649 | return 0; |
12e41d03 DL |
650 | } |
651 | ||
12e41d03 DL |
652 | static int mroute_read(struct thread *t) |
653 | { | |
8ea5d944 | 654 | struct pim_instance *pim; |
d62a17ae | 655 | static long long count; |
656 | char buf[10000]; | |
657 | int result = 0; | |
658 | int cont = 1; | |
d62a17ae | 659 | int rd; |
90450a3d | 660 | ifindex_t ifindex; |
8ea5d944 | 661 | pim = THREAD_ARG(t); |
d62a17ae | 662 | |
663 | while (cont) { | |
90450a3d DS |
664 | rd = pim_socket_recvfromto(pim->mroute_socket, (uint8_t *)buf, |
665 | sizeof(buf), NULL, NULL, NULL, NULL, | |
666 | &ifindex); | |
61e99c94 | 667 | if (rd <= 0) { |
d62a17ae | 668 | if (errno == EINTR) |
669 | continue; | |
670 | if (errno == EWOULDBLOCK || errno == EAGAIN) | |
671 | break; | |
672 | ||
673 | if (PIM_DEBUG_MROUTE) | |
674 | zlog_warn( | |
61e99c94 | 675 | "%s: failure reading rd=%d: fd=%d: errno=%d: %s", |
8ea5d944 DS |
676 | __PRETTY_FUNCTION__, rd, |
677 | pim->mroute_socket, errno, | |
d62a17ae | 678 | safe_strerror(errno)); |
679 | goto done; | |
680 | } | |
681 | ||
90450a3d | 682 | result = pim_mroute_msg(pim, buf, rd, ifindex); |
d62a17ae | 683 | |
684 | count++; | |
685 | if (count % qpim_packet_process == 0) | |
686 | cont = 0; | |
687 | } | |
688 | /* Keep reading */ | |
689 | done: | |
8ea5d944 | 690 | mroute_read_on(pim); |
12e41d03 | 691 | |
d62a17ae | 692 | return result; |
12e41d03 DL |
693 | } |
694 | ||
8ea5d944 | 695 | static void mroute_read_on(struct pim_instance *pim) |
12e41d03 | 696 | { |
f509d941 | 697 | thread_add_read(master, mroute_read, pim, pim->mroute_socket, |
8ea5d944 | 698 | &pim->thread); |
12e41d03 DL |
699 | } |
700 | ||
8ea5d944 | 701 | static void mroute_read_off(struct pim_instance *pim) |
12e41d03 | 702 | { |
8ea5d944 | 703 | THREAD_OFF(pim->thread); |
12e41d03 DL |
704 | } |
705 | ||
6beed987 | 706 | int pim_mroute_socket_enable(struct pim_instance *pim) |
12e41d03 | 707 | { |
d62a17ae | 708 | int fd; |
12e41d03 | 709 | |
d62a17ae | 710 | if (pimd_privs.change(ZPRIVS_RAISE)) |
711 | zlog_err("pim_mroute_socket_enable: could not raise privs, %s", | |
712 | safe_strerror(errno)); | |
12e41d03 | 713 | |
d62a17ae | 714 | fd = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP); |
12e41d03 | 715 | |
e691f179 DS |
716 | if (fd < 0) { |
717 | zlog_warn("Could not create mroute socket: errno=%d: %s", errno, | |
718 | safe_strerror(errno)); | |
719 | return -2; | |
720 | } | |
721 | ||
466e4e5b | 722 | #ifdef SO_BINDTODEVICE |
d1ee84e9 DS |
723 | if (pim->vrf->vrf_id != VRF_DEFAULT && |
724 | setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, pim->vrf->name, | |
e691f179 DS |
725 | strlen(pim->vrf->name))) { |
726 | zlog_warn("Could not setsockopt SO_BINDTODEVICE: %s", | |
727 | safe_strerror(errno)); | |
728 | close(fd); | |
729 | return -3; | |
730 | } | |
466e4e5b | 731 | #endif |
90450a3d | 732 | |
d62a17ae | 733 | if (pimd_privs.change(ZPRIVS_LOWER)) |
734 | zlog_err("pim_mroute_socket_enable: could not lower privs, %s", | |
735 | safe_strerror(errno)); | |
12e41d03 | 736 | |
cdbfaec5 DS |
737 | pim->mroute_socket = fd; |
738 | if (pim_mroute_set(pim, 1)) { | |
d62a17ae | 739 | zlog_warn( |
740 | "Could not enable mroute on socket fd=%d: errno=%d: %s", | |
741 | fd, errno, safe_strerror(errno)); | |
742 | close(fd); | |
cdbfaec5 | 743 | pim->mroute_socket = -1; |
d62a17ae | 744 | return -3; |
745 | } | |
12e41d03 | 746 | |
6beed987 | 747 | pim->mroute_socket_creation = pim_time_monotonic_sec(); |
b45cefcb | 748 | |
8ea5d944 | 749 | mroute_read_on(pim); |
12e41d03 | 750 | |
d62a17ae | 751 | return 0; |
12e41d03 DL |
752 | } |
753 | ||
6beed987 | 754 | int pim_mroute_socket_disable(struct pim_instance *pim) |
12e41d03 | 755 | { |
cdbfaec5 | 756 | if (pim_mroute_set(pim, 0)) { |
d62a17ae | 757 | zlog_warn( |
758 | "Could not disable mroute on socket fd=%d: errno=%d: %s", | |
405d6357 | 759 | pim->mroute_socket, errno, safe_strerror(errno)); |
d62a17ae | 760 | return -2; |
761 | } | |
762 | ||
6beed987 | 763 | if (close(pim->mroute_socket)) { |
d62a17ae | 764 | zlog_warn("Failure closing mroute socket: fd=%d errno=%d: %s", |
405d6357 | 765 | pim->mroute_socket, errno, safe_strerror(errno)); |
d62a17ae | 766 | return -3; |
767 | } | |
768 | ||
8ea5d944 | 769 | mroute_read_off(pim); |
6beed987 | 770 | pim->mroute_socket = -1; |
d62a17ae | 771 | |
772 | return 0; | |
12e41d03 DL |
773 | } |
774 | ||
775 | /* | |
776 | For each network interface (e.g., physical or a virtual tunnel) that | |
777 | would be used for multicast forwarding, a corresponding multicast | |
778 | interface must be added to the kernel. | |
779 | */ | |
d62a17ae | 780 | int pim_mroute_add_vif(struct interface *ifp, struct in_addr ifaddr, |
781 | unsigned char flags) | |
12e41d03 | 782 | { |
d62a17ae | 783 | struct pim_interface *pim_ifp = ifp->info; |
784 | struct vifctl vc; | |
785 | int err; | |
12e41d03 | 786 | |
08f4f901 | 787 | if (PIM_DEBUG_MROUTE) |
d62fd596 DS |
788 | zlog_debug("%s: Add Vif %d (%s[%s])", __PRETTY_FUNCTION__, |
789 | pim_ifp->mroute_vif_index, | |
790 | ifp->name, pim_ifp->pim->vrf->name); | |
08f4f901 | 791 | |
d62a17ae | 792 | memset(&vc, 0, sizeof(vc)); |
793 | vc.vifc_vifi = pim_ifp->mroute_vif_index; | |
b3f2bf7c | 794 | #ifdef VIFF_USE_IFINDEX |
d62a17ae | 795 | vc.vifc_lcl_ifindex = ifp->ifindex; |
b3f2bf7c | 796 | #else |
d62a17ae | 797 | if (ifaddr.s_addr == INADDR_ANY) { |
798 | zlog_warn( | |
799 | "%s: unnumbered interfaces are not supported on this platform", | |
800 | __PRETTY_FUNCTION__); | |
801 | return -1; | |
802 | } | |
803 | memcpy(&vc.vifc_lcl_addr, &ifaddr, sizeof(vc.vifc_lcl_addr)); | |
b3f2bf7c | 804 | #endif |
d62a17ae | 805 | vc.vifc_flags = flags; |
806 | vc.vifc_threshold = PIM_MROUTE_MIN_TTL; | |
807 | vc.vifc_rate_limit = 0; | |
808 | ||
809 | #ifdef PIM_DVMRP_TUNNEL | |
810 | if (vc.vifc_flags & VIFF_TUNNEL) { | |
811 | memcpy(&vc.vifc_rmt_addr, &vif_remote_addr, | |
812 | sizeof(vc.vifc_rmt_addr)); | |
813 | } | |
12e41d03 DL |
814 | #endif |
815 | ||
ea3d967b | 816 | err = setsockopt(pim_ifp->pim->mroute_socket, IPPROTO_IP, MRT_ADD_VIF, |
d62a17ae | 817 | (void *)&vc, sizeof(vc)); |
818 | if (err) { | |
819 | char ifaddr_str[INET_ADDRSTRLEN]; | |
12e41d03 | 820 | |
d62a17ae | 821 | pim_inet4_dump("<ifaddr?>", ifaddr, ifaddr_str, |
822 | sizeof(ifaddr_str)); | |
12e41d03 | 823 | |
d62a17ae | 824 | zlog_warn( |
08f4f901 DS |
825 | "%s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_VIF,vif_index=%d,ifaddr=%s,flag=%d): errno=%d: %s", |
826 | __PRETTY_FUNCTION__, | |
ea3d967b DS |
827 | pim_ifp->pim->mroute_socket, ifp->ifindex, ifaddr_str, |
828 | flags, errno, safe_strerror(errno)); | |
d62a17ae | 829 | return -2; |
830 | } | |
12e41d03 | 831 | |
d62a17ae | 832 | return 0; |
12e41d03 DL |
833 | } |
834 | ||
ea3d967b | 835 | int pim_mroute_del_vif(struct interface *ifp) |
12e41d03 | 836 | { |
ea3d967b | 837 | struct pim_interface *pim_ifp = ifp->info; |
d62a17ae | 838 | struct vifctl vc; |
839 | int err; | |
840 | ||
ea3d967b | 841 | if (PIM_DEBUG_MROUTE) |
d62fd596 | 842 | zlog_debug("%s: Del Vif %d (%s[%s])", __PRETTY_FUNCTION__, |
08f4f901 | 843 | pim_ifp->mroute_vif_index, |
d62fd596 | 844 | ifp->name, pim_ifp->pim->vrf->name); |
12e41d03 | 845 | |
d62a17ae | 846 | memset(&vc, 0, sizeof(vc)); |
ea3d967b | 847 | vc.vifc_vifi = pim_ifp->mroute_vif_index; |
d62a17ae | 848 | |
ea3d967b | 849 | err = setsockopt(pim_ifp->pim->mroute_socket, IPPROTO_IP, MRT_DEL_VIF, |
d62a17ae | 850 | (void *)&vc, sizeof(vc)); |
851 | if (err) { | |
852 | zlog_warn( | |
853 | "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_VIF,vif_index=%d): errno=%d: %s", | |
ea3d967b DS |
854 | __FILE__, __PRETTY_FUNCTION__, |
855 | pim_ifp->pim->mroute_socket, pim_ifp->mroute_vif_index, | |
856 | errno, safe_strerror(errno)); | |
d62a17ae | 857 | return -2; |
858 | } | |
12e41d03 | 859 | |
d62a17ae | 860 | return 0; |
12e41d03 DL |
861 | } |
862 | ||
6a78764e | 863 | int pim_mroute_add(struct channel_oil *c_oil, const char *name) |
12e41d03 | 864 | { |
9a0f71c9 | 865 | struct pim_instance *pim = c_oil->pim; |
d62a17ae | 866 | int err; |
867 | int orig = 0; | |
868 | int orig_iif_vif = 0; | |
869 | ||
856e863f DS |
870 | pim->mroute_add_last = pim_time_monotonic_sec(); |
871 | ++pim->mroute_add_events; | |
d62a17ae | 872 | |
873 | /* Do not install route if incoming interface is undefined. */ | |
874 | if (c_oil->oil.mfcc_parent >= MAXVIFS) { | |
875 | if (PIM_DEBUG_MROUTE) { | |
876 | char buf[1000]; | |
877 | zlog_debug( | |
878 | "%s(%s) %s Attempting to add vifi that is invalid to mroute table", | |
879 | __PRETTY_FUNCTION__, name, | |
880 | pim_channel_oil_dump(c_oil, buf, sizeof(buf))); | |
881 | } | |
882 | return -2; | |
883 | } | |
d3aded99 | 884 | |
d62a17ae | 885 | /* The linux kernel *expects* the incoming |
886 | * vif to be part of the outgoing list | |
887 | * in the case of a (*,G). | |
888 | */ | |
889 | if (c_oil->oil.mfcc_origin.s_addr == INADDR_ANY) { | |
890 | orig = c_oil->oil.mfcc_ttls[c_oil->oil.mfcc_parent]; | |
891 | c_oil->oil.mfcc_ttls[c_oil->oil.mfcc_parent] = 1; | |
892 | } | |
d3aded99 | 893 | |
d62a17ae | 894 | /* |
895 | * If we have an unresolved cache entry for the S,G | |
896 | * it is owned by the pimreg for the incoming IIF | |
897 | * So set pimreg as the IIF temporarily to cause | |
898 | * the packets to be forwarded. Then set it | |
899 | * to the correct IIF afterwords. | |
900 | */ | |
901 | if (!c_oil->installed && c_oil->oil.mfcc_origin.s_addr != INADDR_ANY | |
902 | && c_oil->oil.mfcc_parent != 0) { | |
903 | orig_iif_vif = c_oil->oil.mfcc_parent; | |
904 | c_oil->oil.mfcc_parent = 0; | |
905 | } | |
856e863f | 906 | err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_ADD_MFC, |
d62a17ae | 907 | &c_oil->oil, sizeof(c_oil->oil)); |
908 | ||
909 | if (!err && !c_oil->installed | |
910 | && c_oil->oil.mfcc_origin.s_addr != INADDR_ANY | |
911 | && orig_iif_vif != 0) { | |
912 | c_oil->oil.mfcc_parent = orig_iif_vif; | |
856e863f | 913 | err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_ADD_MFC, |
d62a17ae | 914 | &c_oil->oil, sizeof(c_oil->oil)); |
915 | } | |
0365f56b | 916 | |
d62a17ae | 917 | if (c_oil->oil.mfcc_origin.s_addr == INADDR_ANY) |
918 | c_oil->oil.mfcc_ttls[c_oil->oil.mfcc_parent] = orig; | |
d3aded99 | 919 | |
d62a17ae | 920 | if (err) { |
921 | zlog_warn( | |
922 | "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_ADD_MFC): errno=%d: %s", | |
856e863f | 923 | __FILE__, __PRETTY_FUNCTION__, pim->mroute_socket, |
d62a17ae | 924 | errno, safe_strerror(errno)); |
925 | return -2; | |
926 | } | |
12e41d03 | 927 | |
d62a17ae | 928 | if (PIM_DEBUG_MROUTE) { |
929 | char buf[1000]; | |
d62fd596 DS |
930 | zlog_debug("%s(%s), vrf %s Added Route: %s", __PRETTY_FUNCTION__, name, |
931 | pim->vrf->name, | |
d62a17ae | 932 | pim_channel_oil_dump(c_oil, buf, sizeof(buf))); |
933 | } | |
6a78764e | 934 | |
d62a17ae | 935 | c_oil->installed = 1; |
936 | return 0; | |
12e41d03 DL |
937 | } |
938 | ||
d62a17ae | 939 | int pim_mroute_del(struct channel_oil *c_oil, const char *name) |
12e41d03 | 940 | { |
9a0f71c9 | 941 | struct pim_instance *pim = c_oil->pim; |
d62a17ae | 942 | int err; |
943 | ||
856e863f DS |
944 | pim->mroute_del_last = pim_time_monotonic_sec(); |
945 | ++pim->mroute_del_events; | |
d62a17ae | 946 | |
947 | if (!c_oil->installed) { | |
948 | if (PIM_DEBUG_MROUTE) { | |
949 | char buf[1000]; | |
950 | zlog_debug( | |
951 | "%s %s: vifi %d for route is %s not installed, do not need to send del req. ", | |
952 | __FILE__, __PRETTY_FUNCTION__, | |
953 | c_oil->oil.mfcc_parent, | |
954 | pim_channel_oil_dump(c_oil, buf, sizeof(buf))); | |
955 | } | |
956 | return -2; | |
957 | } | |
12e41d03 | 958 | |
856e863f | 959 | err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_DEL_MFC, |
d62a17ae | 960 | &c_oil->oil, sizeof(c_oil->oil)); |
961 | if (err) { | |
962 | if (PIM_DEBUG_MROUTE) | |
963 | zlog_warn( | |
964 | "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP,MRT_DEL_MFC): errno=%d: %s", | |
965 | __FILE__, __PRETTY_FUNCTION__, | |
856e863f | 966 | pim->mroute_socket, errno, |
d62a17ae | 967 | safe_strerror(errno)); |
968 | return -2; | |
969 | } | |
429a291b | 970 | |
d62a17ae | 971 | if (PIM_DEBUG_MROUTE) { |
972 | char buf[1000]; | |
d62fd596 DS |
973 | zlog_debug("%s(%s), vrf %s Deleted Route: %s", __PRETTY_FUNCTION__, |
974 | name, pim->vrf->name, | |
975 | pim_channel_oil_dump(c_oil, buf, sizeof(buf))); | |
d62a17ae | 976 | } |
781a1745 | 977 | |
d62a17ae | 978 | // Reset kernel installed flag |
979 | c_oil->installed = 0; | |
58302dc7 | 980 | |
d62a17ae | 981 | return 0; |
12e41d03 | 982 | } |
3667e8a0 | 983 | |
d62a17ae | 984 | void pim_mroute_update_counters(struct channel_oil *c_oil) |
3667e8a0 | 985 | { |
9a0f71c9 | 986 | struct pim_instance *pim = c_oil->pim; |
d62a17ae | 987 | struct sioc_sg_req sgreq; |
988 | ||
989 | c_oil->cc.oldpktcnt = c_oil->cc.pktcnt; | |
990 | c_oil->cc.oldbytecnt = c_oil->cc.bytecnt; | |
991 | c_oil->cc.oldwrong_if = c_oil->cc.wrong_if; | |
992 | ||
993 | if (!c_oil->installed) { | |
19b807ca | 994 | c_oil->cc.lastused = 100 * pim->keep_alive_time; |
d62a17ae | 995 | if (PIM_DEBUG_MROUTE) { |
996 | struct prefix_sg sg; | |
997 | ||
998 | sg.src = c_oil->oil.mfcc_origin; | |
999 | sg.grp = c_oil->oil.mfcc_mcastgrp; | |
1000 | if (PIM_DEBUG_MROUTE) | |
1001 | zlog_debug( | |
1002 | "Channel(%s) is not installed no need to collect data from kernel", | |
1003 | pim_str_sg_dump(&sg)); | |
1004 | } | |
1005 | return; | |
c7b1183f | 1006 | } |
c7b1183f | 1007 | |
d62a17ae | 1008 | memset(&sgreq, 0, sizeof(sgreq)); |
1009 | sgreq.src = c_oil->oil.mfcc_origin; | |
1010 | sgreq.grp = c_oil->oil.mfcc_mcastgrp; | |
1011 | ||
1012 | pim_zlookup_sg_statistics(c_oil); | |
856e863f | 1013 | if (ioctl(pim->mroute_socket, SIOCGETSGCNT, &sgreq)) { |
d62a17ae | 1014 | if (PIM_DEBUG_MROUTE) { |
1015 | struct prefix_sg sg; | |
1016 | ||
1017 | sg.src = c_oil->oil.mfcc_origin; | |
1018 | sg.grp = c_oil->oil.mfcc_mcastgrp; | |
1019 | ||
1020 | zlog_warn( | |
1021 | "ioctl(SIOCGETSGCNT=%lu) failure for (S,G)=(%s): errno=%d: %s", | |
1022 | (unsigned long)SIOCGETSGCNT, | |
1023 | pim_str_sg_dump(&sg), errno, | |
1024 | safe_strerror(errno)); | |
1025 | } | |
1026 | return; | |
c7b1183f | 1027 | } |
3667e8a0 | 1028 | |
d62a17ae | 1029 | c_oil->cc.pktcnt = sgreq.pktcnt; |
1030 | c_oil->cc.bytecnt = sgreq.bytecnt; | |
1031 | c_oil->cc.wrong_if = sgreq.wrong_if; | |
3667e8a0 | 1032 | |
d62a17ae | 1033 | return; |
3667e8a0 | 1034 | } |