Skip to content

Commit 7bc570c

Browse files
committed
[IPV6] MROUTE: Support multicast forwarding.
Based on ancient patch by Mickael Hoerdt <[email protected]>, which is available at <http://www-r2.u-strasbg.fr/~hoerdt/dev/linux_ipv6_mforwarding/patch-linux-ipv6-mforwarding-0.1a>. Signed-off-by: YOSHIFUJI Hideaki <[email protected]>
1 parent 80a9492 commit 7bc570c

File tree

13 files changed

+1754
-30
lines changed

13 files changed

+1754
-30
lines changed

include/linux/Kbuild

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ unifdef-y += mempolicy.h
261261
unifdef-y += mii.h
262262
unifdef-y += mman.h
263263
unifdef-y += mroute.h
264+
unifdef-y += mroute6.h
264265
unifdef-y += msdos_fs.h
265266
unifdef-y += msg.h
266267
unifdef-y += nbd.h

include/linux/ipv6.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,9 @@ struct ipv6_devconf {
159159
__s32 accept_source_route;
160160
#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
161161
__s32 optimistic_dad;
162+
#endif
163+
#ifdef CONFIG_IPV6_MROUTE
164+
__s32 mc_forwarding;
162165
#endif
163166
void *sysctl;
164167
};
@@ -190,6 +193,7 @@ enum {
190193
DEVCONF_PROXY_NDP,
191194
DEVCONF_OPTIMISTIC_DAD,
192195
DEVCONF_ACCEPT_SOURCE_ROUTE,
196+
DEVCONF_MC_FORWARDING,
193197
DEVCONF_MAX
194198
};
195199

@@ -230,6 +234,7 @@ struct inet6_skb_parm {
230234
#endif
231235

232236
#define IP6SKB_XFRM_TRANSFORMED 1
237+
#define IP6SKB_FORWARDED 2
233238
};
234239

235240
#define IP6CB(skb) ((struct inet6_skb_parm*)((skb)->cb))

include/linux/mroute6.h

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
#ifndef __LINUX_MROUTE6_H
2+
#define __LINUX_MROUTE6_H
3+
4+
#include <linux/types.h>
5+
#include <linux/sockios.h>
6+
7+
/*
8+
* Based on the MROUTING 3.5 defines primarily to keep
9+
* source compatibility with BSD.
10+
*
11+
* See the pim6sd code for the original history.
12+
*
13+
* Protocol Independent Multicast (PIM) data structures included
14+
* Carlos Picoto ([email protected])
15+
*
16+
*/
17+
18+
#define MRT6_BASE 200
19+
#define MRT6_INIT (MRT6_BASE) /* Activate the kernel mroute code */
20+
#define MRT6_DONE (MRT6_BASE+1) /* Shutdown the kernel mroute */
21+
#define MRT6_ADD_MIF (MRT6_BASE+2) /* Add a virtual interface */
22+
#define MRT6_DEL_MIF (MRT6_BASE+3) /* Delete a virtual interface */
23+
#define MRT6_ADD_MFC (MRT6_BASE+4) /* Add a multicast forwarding entry */
24+
#define MRT6_DEL_MFC (MRT6_BASE+5) /* Delete a multicast forwarding entry */
25+
#define MRT6_VERSION (MRT6_BASE+6) /* Get the kernel multicast version */
26+
27+
#define SIOCGETMIFCNT_IN6 SIOCPROTOPRIVATE /* IP protocol privates */
28+
#define SIOCGETSGCNT_IN6 (SIOCPROTOPRIVATE+1)
29+
#define SIOCGETRPF (SIOCPROTOPRIVATE+2)
30+
31+
#define MAXMIFS 32
32+
typedef unsigned long mifbitmap_t; /* User mode code depends on this lot */
33+
typedef unsigned short mifi_t;
34+
#define ALL_MIFS ((mifi_t)(-1))
35+
36+
#ifndef IF_SETSIZE
37+
#define IF_SETSIZE 256
38+
#endif
39+
40+
typedef __u32 if_mask;
41+
#define NIFBITS (sizeof(if_mask) * 8) /* bits per mask */
42+
43+
#if !defined(__KERNEL__) && !defined(DIV_ROUND_UP)
44+
#define DIV_ROUND_UP(x,y) (((x) + ((y) - 1)) / (y))
45+
#endif
46+
47+
typedef struct if_set {
48+
if_mask ifs_bits[DIV_ROUND_UP(IF_SETSIZE, NIFBITS)];
49+
} if_set;
50+
51+
#define IF_SET(n, p) ((p)->ifs_bits[(n)/NIFBITS] |= (1 << ((n) % NIFBITS)))
52+
#define IF_CLR(n, p) ((p)->ifs_bits[(n)/NIFBITS] &= ~(1 << ((n) % NIFBITS)))
53+
#define IF_ISSET(n, p) ((p)->ifs_bits[(n)/NIFBITS] & (1 << ((n) % NIFBITS)))
54+
#define IF_COPY(f, t) bcopy(f, t, sizeof(*(f)))
55+
#define IF_ZERO(p) bzero(p, sizeof(*(p)))
56+
57+
/*
58+
* Passed by mrouted for an MRT_ADD_MIF - again we use the
59+
* mrouted 3.6 structures for compatibility
60+
*/
61+
62+
struct mif6ctl {
63+
mifi_t mif6c_mifi; /* Index of MIF */
64+
unsigned char mif6c_flags; /* MIFF_ flags */
65+
unsigned char vifc_threshold; /* ttl limit */
66+
u_short mif6c_pifi; /* the index of the physical IF */
67+
unsigned int vifc_rate_limit; /* Rate limiter values (NI) */
68+
};
69+
70+
#define MIFF_REGISTER 0x1 /* register vif */
71+
72+
/*
73+
* Cache manipulation structures for mrouted and PIMd
74+
*/
75+
76+
struct mf6cctl
77+
{
78+
struct sockaddr_in6 mf6cc_origin; /* Origin of mcast */
79+
struct sockaddr_in6 mf6cc_mcastgrp; /* Group in question */
80+
mifi_t mf6cc_parent; /* Where it arrived */
81+
struct if_set mf6cc_ifset; /* Where it is going */
82+
};
83+
84+
/*
85+
* Group count retrieval for pim6sd
86+
*/
87+
88+
struct sioc_sg_req6
89+
{
90+
struct sockaddr_in6 src;
91+
struct sockaddr_in6 grp;
92+
unsigned long pktcnt;
93+
unsigned long bytecnt;
94+
unsigned long wrong_if;
95+
};
96+
97+
/*
98+
* To get vif packet counts
99+
*/
100+
101+
struct sioc_mif_req6
102+
{
103+
mifi_t mifi; /* Which iface */
104+
unsigned long icount; /* In packets */
105+
unsigned long ocount; /* Out packets */
106+
unsigned long ibytes; /* In bytes */
107+
unsigned long obytes; /* Out bytes */
108+
};
109+
110+
/*
111+
* That's all usermode folks
112+
*/
113+
114+
#ifdef __KERNEL__
115+
116+
#include <linux/skbuff.h> /* for struct sk_buff_head */
117+
118+
struct net_device;
119+
struct inet6_dev *ipv6_find_idev(struct net_device *dev);
120+
121+
#ifdef CONFIG_IPV6_MROUTE
122+
static inline int ip6_mroute_opt(int opt)
123+
{
124+
return (opt >= MRT6_BASE) && (opt <= MRT6_BASE + 10);
125+
}
126+
#else
127+
static inline int ip6_mroute_opt(int opt)
128+
{
129+
return 0;
130+
}
131+
#endif
132+
133+
struct sock;
134+
135+
extern int ip6_mroute_setsockopt(struct sock *, int, char __user *, int);
136+
extern int ip6_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
137+
extern int ip6_mr_input(struct sk_buff *skb);
138+
extern int ip6mr_ioctl(struct sock *sk, int cmd, void __user *arg);
139+
extern void ip6_mr_init(void);
140+
141+
struct mif_device
142+
{
143+
struct net_device *dev; /* Device we are using */
144+
unsigned long bytes_in,bytes_out;
145+
unsigned long pkt_in,pkt_out; /* Statistics */
146+
unsigned long rate_limit; /* Traffic shaping (NI) */
147+
unsigned char threshold; /* TTL threshold */
148+
unsigned short flags; /* Control flags */
149+
int link; /* Physical interface index */
150+
};
151+
152+
#define VIFF_STATIC 0x8000
153+
154+
struct mfc6_cache
155+
{
156+
struct mfc6_cache *next; /* Next entry on cache line */
157+
struct in6_addr mf6c_mcastgrp; /* Group the entry belongs to */
158+
struct in6_addr mf6c_origin; /* Source of packet */
159+
mifi_t mf6c_parent; /* Source interface */
160+
int mfc_flags; /* Flags on line */
161+
162+
union {
163+
struct {
164+
unsigned long expires;
165+
struct sk_buff_head unresolved; /* Unresolved buffers */
166+
} unres;
167+
struct {
168+
unsigned long last_assert;
169+
int minvif;
170+
int maxvif;
171+
unsigned long bytes;
172+
unsigned long pkt;
173+
unsigned long wrong_if;
174+
unsigned char ttls[MAXMIFS]; /* TTL thresholds */
175+
} res;
176+
} mfc_un;
177+
};
178+
179+
#define MFC_STATIC 1
180+
#define MFC_NOTIFY 2
181+
182+
#define MFC6_LINES 64
183+
184+
#define MFC6_HASH(a, g) (((__force u32)(a)->s6_addr32[0] ^ \
185+
(__force u32)(a)->s6_addr32[1] ^ \
186+
(__force u32)(a)->s6_addr32[2] ^ \
187+
(__force u32)(a)->s6_addr32[3] ^ \
188+
(__force u32)(g)->s6_addr32[0] ^ \
189+
(__force u32)(g)->s6_addr32[1] ^ \
190+
(__force u32)(g)->s6_addr32[2] ^ \
191+
(__force u32)(g)->s6_addr32[3]) % MFC6_LINES)
192+
193+
#define MFC_ASSERT_THRESH (3*HZ) /* Maximal freq. of asserts */
194+
195+
#endif
196+
197+
#ifdef __KERNEL__
198+
struct rtmsg;
199+
extern int ip6mr_get_route(struct sk_buff *skb, struct rtmsg *rtm, int nowait);
200+
201+
#ifdef CONFIG_IPV6_MROUTE
202+
extern struct sock *mroute6_socket;
203+
extern int ip6mr_sk_done(struct sock *sk);
204+
#else
205+
#define mroute6_socket NULL
206+
static inline int ip6mr_sk_done(struct sock *sk) { return 0; }
207+
#endif
208+
#endif
209+
210+
/*
211+
* Structure used to communicate from kernel to multicast router.
212+
* We'll overlay the structure onto an MLD header (not an IPv6 heder like igmpmsg{}
213+
* used for IPv4 implementation). This is because this structure will be passed via an
214+
* IPv6 raw socket, on wich an application will only receiver the payload i.e the data after
215+
* the IPv6 header and all the extension headers. (See section 3 of RFC 3542)
216+
*/
217+
218+
struct mrt6msg {
219+
#define MRT6MSG_NOCACHE 1
220+
__u8 im6_mbz; /* must be zero */
221+
__u8 im6_msgtype; /* what type of message */
222+
__u16 im6_mif; /* mif rec'd on */
223+
__u32 im6_pad; /* padding for 64 bit arch */
224+
struct in6_addr im6_src, im6_dst;
225+
};
226+
227+
#endif

net/ipv6/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,10 @@ config IPV6_SUBTREES
209209

210210
If unsure, say N.
211211

212+
config IPV6_MROUTE
213+
bool "IPv6: multicast routing (EXPERIMENTAL)"
214+
depends on IPV6 && EXPERIMENTAL
215+
---help---
216+
Experimental support for IPv6 multicast forwarding.
217+
If unsure, say N.
218+

net/ipv6/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ ipv6-objs := af_inet6.o anycast.o ip6_output.o ip6_input.o addrconf.o \
1111
exthdrs.o datagram.o ip6_flowlabel.o inet6_connection_sock.o
1212

1313
ipv6-$(CONFIG_SYSCTL) = sysctl_net_ipv6.o
14+
ipv6-$(CONFIG_IPV6_MROUTE) += ip6mr.o
15+
1416
ipv6-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o \
1517
xfrm6_output.o
1618
ipv6-$(CONFIG_NETFILTER) += netfilter.o

net/ipv6/addrconf.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static struct inet6_dev * ipv6_add_dev(struct net_device *dev)
412412
return ndev;
413413
}
414414

415-
static struct inet6_dev * ipv6_find_idev(struct net_device *dev)
415+
struct inet6_dev * ipv6_find_idev(struct net_device *dev)
416416
{
417417
struct inet6_dev *idev;
418418

@@ -3547,6 +3547,9 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
35473547
#ifdef CONFIG_IPV6_OPTIMISTIC_DAD
35483548
array[DEVCONF_OPTIMISTIC_DAD] = cnf->optimistic_dad;
35493549
#endif
3550+
#ifdef CONFIG_IPV6_MROUTE
3551+
array[DEVCONF_MC_FORWARDING] = cnf->mc_forwarding;
3552+
#endif
35503553
}
35513554

35523555
static inline size_t inet6_if_nlmsg_size(void)
@@ -4094,6 +4097,16 @@ static struct addrconf_sysctl_table
40944097
.proc_handler = &proc_dointvec,
40954098

40964099
},
4100+
#endif
4101+
#ifdef CONFIG_IPV6_MROUTE
4102+
{
4103+
.ctl_name = CTL_UNNUMBERED,
4104+
.procname = "mc_forwarding",
4105+
.data = &ipv6_devconf.mc_forwarding,
4106+
.maxlen = sizeof(int),
4107+
.mode = 0644,
4108+
.proc_handler = &proc_dointvec,
4109+
},
40974110
#endif
40984111
{
40994112
.ctl_name = 0, /* sentinel */

net/ipv6/af_inet6.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@
6161

6262
#include <asm/uaccess.h>
6363
#include <asm/system.h>
64+
#ifdef CONFIG_IPV6_MROUTE
65+
#include <linux/mroute6.h>
66+
#endif
6467

6568
MODULE_AUTHOR("Cast of dozens");
6669
MODULE_DESCRIPTION("IPv6 protocol stack for Linux");
@@ -953,6 +956,9 @@ static int __init inet6_init(void)
953956
err = icmpv6_init();
954957
if (err)
955958
goto icmp_fail;
959+
#ifdef CONFIG_IPV6_MROUTE
960+
ip6_mr_init();
961+
#endif
956962
err = ndisc_init();
957963
if (err)
958964
goto ndisc_fail;

0 commit comments

Comments
 (0)