Deleted Added
full compact
ip6_mroute.c (165118) ip6_mroute.c (166938)
1/* $FreeBSD: head/sys/netinet6/ip6_mroute.c 165118 2006-12-12 12:17:58Z bz $ */
1/* $FreeBSD: head/sys/netinet6/ip6_mroute.c 166938 2007-02-24 11:38:47Z bms $ */
2/* $KAME: ip6_mroute.c,v 1.58 2001/12/18 02:36:31 itojun Exp $ */
3
4/*-
5 * Copyright (C) 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions

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

91#include <sys/malloc.h>
92#include <sys/mbuf.h>
93#include <sys/protosw.h>
94#include <sys/signalvar.h>
95#include <sys/socket.h>
96#include <sys/socketvar.h>
97#include <sys/sockio.h>
98#include <sys/sx.h>
2/* $KAME: ip6_mroute.c,v 1.58 2001/12/18 02:36:31 itojun Exp $ */
3
4/*-
5 * Copyright (C) 1998 WIDE Project.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions

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

91#include <sys/malloc.h>
92#include <sys/mbuf.h>
93#include <sys/protosw.h>
94#include <sys/signalvar.h>
95#include <sys/socket.h>
96#include <sys/socketvar.h>
97#include <sys/sockio.h>
98#include <sys/sx.h>
99#include <sys/sysctl.h>
99#include <sys/syslog.h>
100#include <sys/systm.h>
101#include <sys/time.h>
102
103#include <net/if.h>
104#include <net/if_types.h>
105#include <net/raw_cb.h>
106#include <net/route.h>
107
108#include <netinet/in.h>
109#include <netinet/in_var.h>
110#include <netinet/icmp6.h>
111
112#include <netinet/ip6.h>
113#include <netinet6/ip6_var.h>
114#include <netinet6/scope6_var.h>
115#include <netinet6/nd6.h>
116#include <netinet6/ip6_mroute.h>
100#include <sys/syslog.h>
101#include <sys/systm.h>
102#include <sys/time.h>
103
104#include <net/if.h>
105#include <net/if_types.h>
106#include <net/raw_cb.h>
107#include <net/route.h>
108
109#include <netinet/in.h>
110#include <netinet/in_var.h>
111#include <netinet/icmp6.h>
112
113#include <netinet/ip6.h>
114#include <netinet6/ip6_var.h>
115#include <netinet6/scope6_var.h>
116#include <netinet6/nd6.h>
117#include <netinet6/ip6_mroute.h>
118#include <netinet6/ip6protosw.h>
117#include <netinet6/pim6.h>
118#include <netinet6/pim6_var.h>
119
120static MALLOC_DEFINE(M_MRTABLE6, "mf6c", "multicast forwarding cache entry");
121
122#define M_HASCL(m) ((m)->m_flags & M_EXT)
123
124static int ip6_mdq __P((struct mbuf *, struct ifnet *, struct mf6c *));
125static void phyint_send __P((struct ip6_hdr *, struct mif6 *, struct mbuf *));
126
127static int set_pim6 __P((int *));
128static int socket_send __P((struct socket *, struct mbuf *,
129 struct sockaddr_in6 *));
130static int register_send __P((struct ip6_hdr *, struct mif6 *,
131 struct mbuf *));
132
119#include <netinet6/pim6.h>
120#include <netinet6/pim6_var.h>
121
122static MALLOC_DEFINE(M_MRTABLE6, "mf6c", "multicast forwarding cache entry");
123
124#define M_HASCL(m) ((m)->m_flags & M_EXT)
125
126static int ip6_mdq __P((struct mbuf *, struct ifnet *, struct mf6c *));
127static void phyint_send __P((struct ip6_hdr *, struct mif6 *, struct mbuf *));
128
129static int set_pim6 __P((int *));
130static int socket_send __P((struct socket *, struct mbuf *,
131 struct sockaddr_in6 *));
132static int register_send __P((struct ip6_hdr *, struct mif6 *,
133 struct mbuf *));
134
135extern struct domain inet6domain;
136struct ip6protosw in6_pim_protosw = {
137 .pr_type = SOCK_RAW,
138 .pr_domain = &inet6domain,
139 .pr_protocol = IPPROTO_PIM,
140 .pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
141 .pr_input = pim6_input,
142 .pr_output = rip6_output,
143 .pr_ctloutput = rip6_ctloutput,
144 .pr_usrreqs = &rip6_usrreqs
145};
146
133/*
134 * Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
135 * except for netstat or debugging purposes.
136 */
137struct socket *ip6_mrouter = NULL;
138int ip6_mrouter_ver = 0;
139int ip6_mrtproto = IPPROTO_PIM; /* for netstat only */
147/*
148 * Globals. All but ip6_mrouter, ip6_mrtproto and mrt6stat could be static,
149 * except for netstat or debugging purposes.
150 */
151struct socket *ip6_mrouter = NULL;
152int ip6_mrouter_ver = 0;
153int ip6_mrtproto = IPPROTO_PIM; /* for netstat only */
154
155SYSCTL_DECL(_net_inet6);
156SYSCTL_DECL(_net_inet6_ip6);
157SYSCTL_NODE(_net_inet6, IPPROTO_PIM, pim, CTLFLAG_RW, 0, "PIM");
158
140struct mrt6stat mrt6stat;
159struct mrt6stat mrt6stat;
160SYSCTL_STRUCT(_net_inet6_ip6, OID_AUTO, mrt6stat, CTLFLAG_RW,
161 &mrt6stat, mrt6stat,
162 "Multicast Routing Statistics (struct mrt6stat, netinet6/ip6_mroute.h)");
141
142#define NO_RTE_FOUND 0x1
143#define RTE_FOUND 0x2
144
145struct mf6c *mf6ctable[MF6CTBLSIZ];
163
164#define NO_RTE_FOUND 0x1
165#define RTE_FOUND 0x2
166
167struct mf6c *mf6ctable[MF6CTBLSIZ];
168SYSCTL_OPAQUE(_net_inet6_ip6, OID_AUTO, mf6ctable, CTLFLAG_RD,
169 &mf6ctable, sizeof(mf6ctable), "S,*mf6ctable[MF6CTBLSIZ]",
170 "Multicast Forwarding Table (struct *mf6ctable[MF6CTBLSIZ], "
171 "netinet6/ip6_mroute.h)");
172
146u_char n6expire[MF6CTBLSIZ];
173u_char n6expire[MF6CTBLSIZ];
174
147static struct mif6 mif6table[MAXMIFS];
175static struct mif6 mif6table[MAXMIFS];
176SYSCTL_OPAQUE(_net_inet6_ip6, OID_AUTO, mif6table, CTLFLAG_RD,
177 &mif6table, sizeof(mif6table), "S,vif[MAXMIFS]",
178 "Multicast Interfaces (struct mif[MAXMIFS], netinet6/ip6_mroute.h)");
179
148#ifdef MRT6DEBUG
149u_int mrt6debug = 0; /* debug level */
150#define DEBUG_MFC 0x02
151#define DEBUG_FORWARD 0x04
152#define DEBUG_EXPIRE 0x08
153#define DEBUG_XMIT 0x10
154#define DEBUG_REG 0x20
155#define DEBUG_PIM 0x40

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

182
183/*
184 * Private variables.
185 */
186static mifi_t nummifs = 0;
187static mifi_t reg_mif_num = (mifi_t)-1;
188
189static struct pim6stat pim6stat;
180#ifdef MRT6DEBUG
181u_int mrt6debug = 0; /* debug level */
182#define DEBUG_MFC 0x02
183#define DEBUG_FORWARD 0x04
184#define DEBUG_EXPIRE 0x08
185#define DEBUG_XMIT 0x10
186#define DEBUG_REG 0x20
187#define DEBUG_PIM 0x40

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

214
215/*
216 * Private variables.
217 */
218static mifi_t nummifs = 0;
219static mifi_t reg_mif_num = (mifi_t)-1;
220
221static struct pim6stat pim6stat;
222SYSCTL_STRUCT(_net_inet6_pim, PIM6CTL_STATS, stats, CTLFLAG_RD,
223 &pim6stat, pim6stat,
224 "PIM Statistics (struct pim6stat, netinet6/pim_var.h)");
225
190static int pim6;
191
192/*
193 * Hash function for a source, group entry
194 */
195#define MF6CHASH(a, g) MF6CHASHMOD((a).s6_addr32[0] ^ (a).s6_addr32[1] ^ \
196 (a).s6_addr32[2] ^ (a).s6_addr32[3] ^ \
197 (g).s6_addr32[0] ^ (g).s6_addr32[1] ^ \

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

256static int ip6_mrouter_init __P((struct socket *, int, int));
257static int add_m6if __P((struct mif6ctl *));
258static int del_m6if __P((mifi_t *));
259static int add_m6fc __P((struct mf6cctl *));
260static int del_m6fc __P((struct mf6cctl *));
261
262static struct callout expire_upcalls_ch;
263
226static int pim6;
227
228/*
229 * Hash function for a source, group entry
230 */
231#define MF6CHASH(a, g) MF6CHASHMOD((a).s6_addr32[0] ^ (a).s6_addr32[1] ^ \
232 (a).s6_addr32[2] ^ (a).s6_addr32[3] ^ \
233 (g).s6_addr32[0] ^ (g).s6_addr32[1] ^ \

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

292static int ip6_mrouter_init __P((struct socket *, int, int));
293static int add_m6if __P((struct mif6ctl *));
294static int del_m6if __P((mifi_t *));
295static int add_m6fc __P((struct mf6cctl *));
296static int del_m6fc __P((struct mf6cctl *));
297
298static struct callout expire_upcalls_ch;
299
300int X_ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m);
301int X_ip6_mrouter_done(void);
302int X_ip6_mrouter_set(struct socket *so, struct sockopt *sopt);
303int X_ip6_mrouter_get(struct socket *so, struct sockopt *sopt);
304int X_mrt6_ioctl(int cmd, caddr_t data);
305
264/*
265 * Handle MRT setsockopt commands to modify the multicast routing tables.
266 */
267int
306/*
307 * Handle MRT setsockopt commands to modify the multicast routing tables.
308 */
309int
268ip6_mrouter_set(so, sopt)
269 struct socket *so;
270 struct sockopt *sopt;
310X_ip6_mrouter_set(struct socket *so, struct sockopt *sopt)
271{
272 int error = 0;
273 int optval;
274 struct mif6ctl mifc;
275 struct mf6cctl mfcc;
276 mifi_t mifi;
277
278 if (so != ip6_mrouter && sopt->sopt_name != MRT6_INIT)

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

285#endif
286 error = sooptcopyin(sopt, &optval, sizeof(optval),
287 sizeof(optval));
288 if (error)
289 break;
290 error = ip6_mrouter_init(so, optval, sopt->sopt_name);
291 break;
292 case MRT6_DONE:
311{
312 int error = 0;
313 int optval;
314 struct mif6ctl mifc;
315 struct mf6cctl mfcc;
316 mifi_t mifi;
317
318 if (so != ip6_mrouter && sopt->sopt_name != MRT6_INIT)

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

325#endif
326 error = sooptcopyin(sopt, &optval, sizeof(optval),
327 sizeof(optval));
328 if (error)
329 break;
330 error = ip6_mrouter_init(so, optval, sopt->sopt_name);
331 break;
332 case MRT6_DONE:
293 error = ip6_mrouter_done();
333 error = X_ip6_mrouter_done();
294 break;
295 case MRT6_ADD_MIF:
296 error = sooptcopyin(sopt, &mifc, sizeof(mifc), sizeof(mifc));
297 if (error)
298 break;
299 error = add_m6if(&mifc);
300 break;
301 case MRT6_ADD_MFC:

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

330
331 return (error);
332}
333
334/*
335 * Handle MRT getsockopt commands
336 */
337int
334 break;
335 case MRT6_ADD_MIF:
336 error = sooptcopyin(sopt, &mifc, sizeof(mifc), sizeof(mifc));
337 if (error)
338 break;
339 error = add_m6if(&mifc);
340 break;
341 case MRT6_ADD_MFC:

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

370
371 return (error);
372}
373
374/*
375 * Handle MRT getsockopt commands
376 */
377int
338ip6_mrouter_get(so, sopt)
339 struct socket *so;
340 struct sockopt *sopt;
378X_ip6_mrouter_get(struct socket *so, struct sockopt *sopt)
341{
342 int error = 0;
343
344 if (so != ip6_mrouter)
345 return (EACCES);
346
347 switch (sopt->sopt_name) {
348 case MRT6_PIM:
349 error = sooptcopyout(sopt, &pim6, sizeof(pim6));
350 break;
351 }
352 return (error);
353}
354
355/*
356 * Handle ioctl commands to obtain information from the cache
357 */
358int
379{
380 int error = 0;
381
382 if (so != ip6_mrouter)
383 return (EACCES);
384
385 switch (sopt->sopt_name) {
386 case MRT6_PIM:
387 error = sooptcopyout(sopt, &pim6, sizeof(pim6));
388 break;
389 }
390 return (error);
391}
392
393/*
394 * Handle ioctl commands to obtain information from the cache
395 */
396int
359mrt6_ioctl(cmd, data)
360 int cmd;
361 caddr_t data;
397X_mrt6_ioctl(int cmd, caddr_t data)
362{
363 switch (cmd) {
364 case SIOCGETSGCNT_IN6:
365 return (get_sg_cnt((struct sioc_sg_req6 *)data));
366 case SIOCGETMIFCNT_IN6:
367 return (get_mif6_cnt((struct sioc_mif_req6 *)data));
368 default:
369 return (EINVAL);

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

473
474 return (0);
475}
476
477/*
478 * Disable multicast routing
479 */
480int
398{
399 switch (cmd) {
400 case SIOCGETSGCNT_IN6:
401 return (get_sg_cnt((struct sioc_sg_req6 *)data));
402 case SIOCGETMIFCNT_IN6:
403 return (get_mif6_cnt((struct sioc_mif_req6 *)data));
404 default:
405 return (EINVAL);

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

509
510 return (0);
511}
512
513/*
514 * Disable multicast routing
515 */
516int
481ip6_mrouter_done()
517X_ip6_mrouter_done(void)
482{
483 mifi_t mifi;
484 int i;
485 struct mf6c *rt;
486 struct rtdetq *rte;
487 int s;
488
489 s = splnet();

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

988 * forwarding a packet from other node). ip6_output(), which is currently the
989 * only function that calls this function is called in the originating context,
990 * explicitly ensures this condition. It is caller's responsibility to ensure
991 * that if this function is called from somewhere else in the originating
992 * context in the future.
993 */
994
995int
518{
519 mifi_t mifi;
520 int i;
521 struct mf6c *rt;
522 struct rtdetq *rte;
523 int s;
524
525 s = splnet();

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

1024 * forwarding a packet from other node). ip6_output(), which is currently the
1025 * only function that calls this function is called in the originating context,
1026 * explicitly ensures this condition. It is caller's responsibility to ensure
1027 * that if this function is called from somewhere else in the originating
1028 * context in the future.
1029 */
1030
1031int
996ip6_mforward(ip6, ifp, m)
997 struct ip6_hdr *ip6;
998 struct ifnet *ifp;
999 struct mbuf *m;
1032X_ip6_mforward(struct ip6_hdr *ip6, struct ifnet *ifp, struct mbuf *m)
1000{
1001 struct mf6c *rt;
1002 struct mif6 *mifp;
1003 struct mbuf *mm;
1004 int s;
1005 mifi_t mifi;
1006 char ip6bufs[INET6_ADDRSTRLEN], ip6bufd[INET6_ADDRSTRLEN];
1007

--- 921 unchanged lines hidden ---
1033{
1034 struct mf6c *rt;
1035 struct mif6 *mifp;
1036 struct mbuf *mm;
1037 int s;
1038 mifi_t mifi;
1039 char ip6bufs[INET6_ADDRSTRLEN], ip6bufd[INET6_ADDRSTRLEN];
1040

--- 921 unchanged lines hidden ---