2 * Linux IPv6 multicast routing support for BSD pim6sd
3 * Based on net/ipv4/ipmr.c.
5 * (c) 2004 Mickael Hoerdt, <hoerdt@clarinet.u-strasbg.fr>
6 * LSIIT Laboratory, Strasbourg, France
7 * (c) 2004 Jean-Philippe Andriot, <jean-philippe.andriot@6WIND.com>
9 * Copyright (C)2007,2008 USAGI/WIDE Project
10 * YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
19 #include <asm/system.h>
20 #include <asm/uaccess.h>
21 #include <linux/types.h>
22 #include <linux/sched.h>
23 #include <linux/errno.h>
24 #include <linux/timer.h>
26 #include <linux/kernel.h>
27 #include <linux/fcntl.h>
28 #include <linux/stat.h>
29 #include <linux/socket.h>
30 #include <linux/inet.h>
31 #include <linux/netdevice.h>
32 #include <linux/inetdevice.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/init.h>
36 #include <net/protocol.h>
37 #include <linux/skbuff.h>
40 #include <linux/notifier.h>
41 #include <linux/if_arp.h>
42 #include <net/checksum.h>
43 #include <net/netlink.h>
46 #include <net/ip6_route.h>
47 #include <linux/mroute6.h>
48 #include <linux/pim.h>
49 #include <net/addrconf.h>
50 #include <linux/netfilter_ipv6.h>
51 #include <net/ip6_checksum.h>
53 /* Big lock, protecting vif table, mrt cache and mroute socket state.
54 Note that the changes are semaphored via rtnl_lock.
57 static DEFINE_RWLOCK(mrt_lock
);
60 * Multicast router control variables
63 #define MIF_EXISTS(_net, _idx) ((_net)->ipv6.vif6_table[_idx].dev != NULL)
65 static struct mfc6_cache
*mfc_unres_queue
; /* Queue of unresolved entries */
67 /* Special spinlock for queue of unresolved entries */
68 static DEFINE_SPINLOCK(mfc_unres_lock
);
70 /* We return to original Alan's scheme. Hash table of resolved
71 entries is changed only in process context and protected
72 with weak lock mrt_lock. Queue of unresolved entries is protected
73 with strong spinlock mfc_unres_lock.
75 In this case data path is free of exclusive locks at all.
78 static struct kmem_cache
*mrt_cachep __read_mostly
;
80 static int ip6_mr_forward(struct sk_buff
*skb
, struct mfc6_cache
*cache
);
81 static int ip6mr_cache_report(struct net
*net
, struct sk_buff
*pkt
,
82 mifi_t mifi
, int assert);
83 static int ip6mr_fill_mroute(struct sk_buff
*skb
, struct mfc6_cache
*c
, struct rtmsg
*rtm
);
84 static void mroute_clean_tables(struct net
*net
);
86 #ifdef CONFIG_IPV6_PIMSM_V2
87 static struct inet6_protocol pim6_protocol
;
90 static struct timer_list ipmr_expire_timer
;
95 struct ipmr_mfc_iter
{
96 struct seq_net_private p
;
97 struct mfc6_cache
**cache
;
102 static struct mfc6_cache
*ipmr_mfc_seq_idx(struct net
*net
,
103 struct ipmr_mfc_iter
*it
, loff_t pos
)
105 struct mfc6_cache
*mfc
;
107 it
->cache
= net
->ipv6
.mfc6_cache_array
;
108 read_lock(&mrt_lock
);
109 for (it
->ct
= 0; it
->ct
< MFC6_LINES
; it
->ct
++)
110 for (mfc
= net
->ipv6
.mfc6_cache_array
[it
->ct
];
111 mfc
; mfc
= mfc
->next
)
114 read_unlock(&mrt_lock
);
116 it
->cache
= &mfc_unres_queue
;
117 spin_lock_bh(&mfc_unres_lock
);
118 for (mfc
= mfc_unres_queue
; mfc
; mfc
= mfc
->next
)
119 if (net_eq(mfc6_net(mfc
), net
) &&
122 spin_unlock_bh(&mfc_unres_lock
);
132 * The /proc interfaces to multicast routing /proc/ip6_mr_cache /proc/ip6_mr_vif
135 struct ipmr_vif_iter
{
136 struct seq_net_private p
;
140 static struct mif_device
*ip6mr_vif_seq_idx(struct net
*net
,
141 struct ipmr_vif_iter
*iter
,
144 for (iter
->ct
= 0; iter
->ct
< net
->ipv6
.maxvif
; ++iter
->ct
) {
145 if (!MIF_EXISTS(net
, iter
->ct
))
148 return &net
->ipv6
.vif6_table
[iter
->ct
];
153 static void *ip6mr_vif_seq_start(struct seq_file
*seq
, loff_t
*pos
)
156 struct net
*net
= seq_file_net(seq
);
158 read_lock(&mrt_lock
);
159 return *pos
? ip6mr_vif_seq_idx(net
, seq
->private, *pos
- 1)
163 static void *ip6mr_vif_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
165 struct ipmr_vif_iter
*iter
= seq
->private;
166 struct net
*net
= seq_file_net(seq
);
169 if (v
== SEQ_START_TOKEN
)
170 return ip6mr_vif_seq_idx(net
, iter
, 0);
172 while (++iter
->ct
< net
->ipv6
.maxvif
) {
173 if (!MIF_EXISTS(net
, iter
->ct
))
175 return &net
->ipv6
.vif6_table
[iter
->ct
];
180 static void ip6mr_vif_seq_stop(struct seq_file
*seq
, void *v
)
183 read_unlock(&mrt_lock
);
186 static int ip6mr_vif_seq_show(struct seq_file
*seq
, void *v
)
188 struct net
*net
= seq_file_net(seq
);
190 if (v
== SEQ_START_TOKEN
) {
192 "Interface BytesIn PktsIn BytesOut PktsOut Flags\n");
194 const struct mif_device
*vif
= v
;
195 const char *name
= vif
->dev
? vif
->dev
->name
: "none";
198 "%2td %-10s %8ld %7ld %8ld %7ld %05X\n",
199 vif
- net
->ipv6
.vif6_table
,
200 name
, vif
->bytes_in
, vif
->pkt_in
,
201 vif
->bytes_out
, vif
->pkt_out
,
207 static struct seq_operations ip6mr_vif_seq_ops
= {
208 .start
= ip6mr_vif_seq_start
,
209 .next
= ip6mr_vif_seq_next
,
210 .stop
= ip6mr_vif_seq_stop
,
211 .show
= ip6mr_vif_seq_show
,
214 static int ip6mr_vif_open(struct inode
*inode
, struct file
*file
)
216 return seq_open_net(inode
, file
, &ip6mr_vif_seq_ops
,
217 sizeof(struct ipmr_vif_iter
));
220 static struct file_operations ip6mr_vif_fops
= {
221 .owner
= THIS_MODULE
,
222 .open
= ip6mr_vif_open
,
225 .release
= seq_release_net
,
228 static void *ipmr_mfc_seq_start(struct seq_file
*seq
, loff_t
*pos
)
230 struct net
*net
= seq_file_net(seq
);
232 return *pos
? ipmr_mfc_seq_idx(net
, seq
->private, *pos
- 1)
236 static void *ipmr_mfc_seq_next(struct seq_file
*seq
, void *v
, loff_t
*pos
)
238 struct mfc6_cache
*mfc
= v
;
239 struct ipmr_mfc_iter
*it
= seq
->private;
240 struct net
*net
= seq_file_net(seq
);
244 if (v
== SEQ_START_TOKEN
)
245 return ipmr_mfc_seq_idx(net
, seq
->private, 0);
250 if (it
->cache
== &mfc_unres_queue
)
253 BUG_ON(it
->cache
!= net
->ipv6
.mfc6_cache_array
);
255 while (++it
->ct
< MFC6_LINES
) {
256 mfc
= net
->ipv6
.mfc6_cache_array
[it
->ct
];
261 /* exhausted cache_array, show unresolved */
262 read_unlock(&mrt_lock
);
263 it
->cache
= &mfc_unres_queue
;
266 spin_lock_bh(&mfc_unres_lock
);
267 mfc
= mfc_unres_queue
;
272 spin_unlock_bh(&mfc_unres_lock
);
278 static void ipmr_mfc_seq_stop(struct seq_file
*seq
, void *v
)
280 struct ipmr_mfc_iter
*it
= seq
->private;
281 struct net
*net
= seq_file_net(seq
);
283 if (it
->cache
== &mfc_unres_queue
)
284 spin_unlock_bh(&mfc_unres_lock
);
285 else if (it
->cache
== net
->ipv6
.mfc6_cache_array
)
286 read_unlock(&mrt_lock
);
289 static int ipmr_mfc_seq_show(struct seq_file
*seq
, void *v
)
292 struct net
*net
= seq_file_net(seq
);
294 if (v
== SEQ_START_TOKEN
) {
298 "Iif Pkts Bytes Wrong Oifs\n");
300 const struct mfc6_cache
*mfc
= v
;
301 const struct ipmr_mfc_iter
*it
= seq
->private;
303 seq_printf(seq
, "%pI6 %pI6 %-3hd",
304 &mfc
->mf6c_mcastgrp
, &mfc
->mf6c_origin
,
307 if (it
->cache
!= &mfc_unres_queue
) {
308 seq_printf(seq
, " %8lu %8lu %8lu",
310 mfc
->mfc_un
.res
.bytes
,
311 mfc
->mfc_un
.res
.wrong_if
);
312 for (n
= mfc
->mfc_un
.res
.minvif
;
313 n
< mfc
->mfc_un
.res
.maxvif
; n
++) {
314 if (MIF_EXISTS(net
, n
) &&
315 mfc
->mfc_un
.res
.ttls
[n
] < 255)
318 n
, mfc
->mfc_un
.res
.ttls
[n
]);
321 /* unresolved mfc_caches don't contain
322 * pkt, bytes and wrong_if values
324 seq_printf(seq
, " %8lu %8lu %8lu", 0ul, 0ul, 0ul);
331 static struct seq_operations ipmr_mfc_seq_ops
= {
332 .start
= ipmr_mfc_seq_start
,
333 .next
= ipmr_mfc_seq_next
,
334 .stop
= ipmr_mfc_seq_stop
,
335 .show
= ipmr_mfc_seq_show
,
338 static int ipmr_mfc_open(struct inode
*inode
, struct file
*file
)
340 return seq_open_net(inode
, file
, &ipmr_mfc_seq_ops
,
341 sizeof(struct ipmr_mfc_iter
));
344 static struct file_operations ip6mr_mfc_fops
= {
345 .owner
= THIS_MODULE
,
346 .open
= ipmr_mfc_open
,
349 .release
= seq_release_net
,
353 #ifdef CONFIG_IPV6_PIMSM_V2
355 static int pim6_rcv(struct sk_buff
*skb
)
357 struct pimreghdr
*pim
;
358 struct ipv6hdr
*encap
;
359 struct net_device
*reg_dev
= NULL
;
360 struct net
*net
= dev_net(skb
->dev
);
361 int reg_vif_num
= net
->ipv6
.mroute_reg_vif_num
;
363 if (!pskb_may_pull(skb
, sizeof(*pim
) + sizeof(*encap
)))
366 pim
= (struct pimreghdr
*)skb_transport_header(skb
);
367 if (pim
->type
!= ((PIM_VERSION
<< 4) | PIM_REGISTER
) ||
368 (pim
->flags
& PIM_NULL_REGISTER
) ||
369 (csum_ipv6_magic(&ipv6_hdr(skb
)->saddr
, &ipv6_hdr(skb
)->daddr
,
370 sizeof(*pim
), IPPROTO_PIM
,
371 csum_partial((void *)pim
, sizeof(*pim
), 0)) &&
372 csum_fold(skb_checksum(skb
, 0, skb
->len
, 0))))
375 /* check if the inner packet is destined to mcast group */
376 encap
= (struct ipv6hdr
*)(skb_transport_header(skb
) +
379 if (!ipv6_addr_is_multicast(&encap
->daddr
) ||
380 encap
->payload_len
== 0 ||
381 ntohs(encap
->payload_len
) + sizeof(*pim
) > skb
->len
)
384 read_lock(&mrt_lock
);
385 if (reg_vif_num
>= 0)
386 reg_dev
= net
->ipv6
.vif6_table
[reg_vif_num
].dev
;
389 read_unlock(&mrt_lock
);
394 skb
->mac_header
= skb
->network_header
;
395 skb_pull(skb
, (u8
*)encap
- skb
->data
);
396 skb_reset_network_header(skb
);
398 skb
->protocol
= htons(ETH_P_IPV6
);
400 skb
->pkt_type
= PACKET_HOST
;
402 reg_dev
->stats
.rx_bytes
+= skb
->len
;
403 reg_dev
->stats
.rx_packets
++;
413 static struct inet6_protocol pim6_protocol
= {
417 /* Service routines creating virtual interfaces: PIMREG */
419 static int reg_vif_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
421 struct net
*net
= dev_net(dev
);
423 read_lock(&mrt_lock
);
424 dev
->stats
.tx_bytes
+= skb
->len
;
425 dev
->stats
.tx_packets
++;
426 ip6mr_cache_report(net
, skb
, net
->ipv6
.mroute_reg_vif_num
,
428 read_unlock(&mrt_lock
);
433 static const struct net_device_ops reg_vif_netdev_ops
= {
434 .ndo_start_xmit
= reg_vif_xmit
,
437 static void reg_vif_setup(struct net_device
*dev
)
439 dev
->type
= ARPHRD_PIMREG
;
440 dev
->mtu
= 1500 - sizeof(struct ipv6hdr
) - 8;
441 dev
->flags
= IFF_NOARP
;
442 dev
->netdev_ops
= ®_vif_netdev_ops
;
443 dev
->destructor
= free_netdev
;
446 static struct net_device
*ip6mr_reg_vif(struct net
*net
)
448 struct net_device
*dev
;
450 dev
= alloc_netdev(0, "pim6reg", reg_vif_setup
);
454 dev_net_set(dev
, net
);
456 if (register_netdevice(dev
)) {
469 /* allow the register to be completed before unregistering. */
473 unregister_netdevice(dev
);
482 static int mif6_delete(struct net
*net
, int vifi
)
484 struct mif_device
*v
;
485 struct net_device
*dev
;
486 struct inet6_dev
*in6_dev
;
487 if (vifi
< 0 || vifi
>= net
->ipv6
.maxvif
)
488 return -EADDRNOTAVAIL
;
490 v
= &net
->ipv6
.vif6_table
[vifi
];
492 write_lock_bh(&mrt_lock
);
497 write_unlock_bh(&mrt_lock
);
498 return -EADDRNOTAVAIL
;
501 #ifdef CONFIG_IPV6_PIMSM_V2
502 if (vifi
== net
->ipv6
.mroute_reg_vif_num
)
503 net
->ipv6
.mroute_reg_vif_num
= -1;
506 if (vifi
+ 1 == net
->ipv6
.maxvif
) {
508 for (tmp
= vifi
- 1; tmp
>= 0; tmp
--) {
509 if (MIF_EXISTS(net
, tmp
))
512 net
->ipv6
.maxvif
= tmp
+ 1;
515 write_unlock_bh(&mrt_lock
);
517 dev_set_allmulti(dev
, -1);
519 in6_dev
= __in6_dev_get(dev
);
521 in6_dev
->cnf
.mc_forwarding
--;
523 if (v
->flags
& MIFF_REGISTER
)
524 unregister_netdevice(dev
);
530 static inline void ip6mr_cache_free(struct mfc6_cache
*c
)
532 release_net(mfc6_net(c
));
533 kmem_cache_free(mrt_cachep
, c
);
536 /* Destroy an unresolved cache entry, killing queued skbs
537 and reporting error to netlink readers.
540 static void ip6mr_destroy_unres(struct mfc6_cache
*c
)
543 struct net
*net
= mfc6_net(c
);
545 atomic_dec(&net
->ipv6
.cache_resolve_queue_len
);
547 while((skb
= skb_dequeue(&c
->mfc_un
.unres
.unresolved
)) != NULL
) {
548 if (ipv6_hdr(skb
)->version
== 0) {
549 struct nlmsghdr
*nlh
= (struct nlmsghdr
*)skb_pull(skb
, sizeof(struct ipv6hdr
));
550 nlh
->nlmsg_type
= NLMSG_ERROR
;
551 nlh
->nlmsg_len
= NLMSG_LENGTH(sizeof(struct nlmsgerr
));
552 skb_trim(skb
, nlh
->nlmsg_len
);
553 ((struct nlmsgerr
*)NLMSG_DATA(nlh
))->error
= -ETIMEDOUT
;
554 rtnl_unicast(skb
, net
, NETLINK_CB(skb
).pid
);
563 /* Single timer process for all the unresolved queue. */
565 static void ipmr_do_expire_process(unsigned long dummy
)
567 unsigned long now
= jiffies
;
568 unsigned long expires
= 10 * HZ
;
569 struct mfc6_cache
*c
, **cp
;
571 cp
= &mfc_unres_queue
;
573 while ((c
= *cp
) != NULL
) {
574 if (time_after(c
->mfc_un
.unres
.expires
, now
)) {
576 unsigned long interval
= c
->mfc_un
.unres
.expires
- now
;
577 if (interval
< expires
)
584 ip6mr_destroy_unres(c
);
587 if (mfc_unres_queue
!= NULL
)
588 mod_timer(&ipmr_expire_timer
, jiffies
+ expires
);
591 static void ipmr_expire_process(unsigned long dummy
)
593 if (!spin_trylock(&mfc_unres_lock
)) {
594 mod_timer(&ipmr_expire_timer
, jiffies
+ 1);
598 if (mfc_unres_queue
!= NULL
)
599 ipmr_do_expire_process(dummy
);
601 spin_unlock(&mfc_unres_lock
);
604 /* Fill oifs list. It is called under write locked mrt_lock. */
606 static void ip6mr_update_thresholds(struct mfc6_cache
*cache
, unsigned char *ttls
)
609 struct net
*net
= mfc6_net(cache
);
611 cache
->mfc_un
.res
.minvif
= MAXMIFS
;
612 cache
->mfc_un
.res
.maxvif
= 0;
613 memset(cache
->mfc_un
.res
.ttls
, 255, MAXMIFS
);
615 for (vifi
= 0; vifi
< net
->ipv6
.maxvif
; vifi
++) {
616 if (MIF_EXISTS(net
, vifi
) &&
617 ttls
[vifi
] && ttls
[vifi
] < 255) {
618 cache
->mfc_un
.res
.ttls
[vifi
] = ttls
[vifi
];
619 if (cache
->mfc_un
.res
.minvif
> vifi
)
620 cache
->mfc_un
.res
.minvif
= vifi
;
621 if (cache
->mfc_un
.res
.maxvif
<= vifi
)
622 cache
->mfc_un
.res
.maxvif
= vifi
+ 1;
627 static int mif6_add(struct net
*net
, struct mif6ctl
*vifc
, int mrtsock
)
629 int vifi
= vifc
->mif6c_mifi
;
630 struct mif_device
*v
= &net
->ipv6
.vif6_table
[vifi
];
631 struct net_device
*dev
;
632 struct inet6_dev
*in6_dev
;
636 if (MIF_EXISTS(net
, vifi
))
639 switch (vifc
->mif6c_flags
) {
640 #ifdef CONFIG_IPV6_PIMSM_V2
643 * Special Purpose VIF in PIM
644 * All the packets will be sent to the daemon
646 if (net
->ipv6
.mroute_reg_vif_num
>= 0)
648 dev
= ip6mr_reg_vif(net
);
651 err
= dev_set_allmulti(dev
, 1);
653 unregister_netdevice(dev
);
660 dev
= dev_get_by_index(net
, vifc
->mif6c_pifi
);
662 return -EADDRNOTAVAIL
;
663 err
= dev_set_allmulti(dev
, 1);
673 in6_dev
= __in6_dev_get(dev
);
675 in6_dev
->cnf
.mc_forwarding
++;
678 * Fill in the VIF structures
680 v
->rate_limit
= vifc
->vifc_rate_limit
;
681 v
->flags
= vifc
->mif6c_flags
;
683 v
->flags
|= VIFF_STATIC
;
684 v
->threshold
= vifc
->vifc_threshold
;
689 v
->link
= dev
->ifindex
;
690 if (v
->flags
& MIFF_REGISTER
)
691 v
->link
= dev
->iflink
;
693 /* And finish update writing critical data */
694 write_lock_bh(&mrt_lock
);
696 #ifdef CONFIG_IPV6_PIMSM_V2
697 if (v
->flags
& MIFF_REGISTER
)
698 net
->ipv6
.mroute_reg_vif_num
= vifi
;
700 if (vifi
+ 1 > net
->ipv6
.maxvif
)
701 net
->ipv6
.maxvif
= vifi
+ 1;
702 write_unlock_bh(&mrt_lock
);
706 static struct mfc6_cache
*ip6mr_cache_find(struct net
*net
,
707 struct in6_addr
*origin
,
708 struct in6_addr
*mcastgrp
)
710 int line
= MFC6_HASH(mcastgrp
, origin
);
711 struct mfc6_cache
*c
;
713 for (c
= net
->ipv6
.mfc6_cache_array
[line
]; c
; c
= c
->next
) {
714 if (ipv6_addr_equal(&c
->mf6c_origin
, origin
) &&
715 ipv6_addr_equal(&c
->mf6c_mcastgrp
, mcastgrp
))
722 * Allocate a multicast cache entry
724 static struct mfc6_cache
*ip6mr_cache_alloc(struct net
*net
)
726 struct mfc6_cache
*c
= kmem_cache_zalloc(mrt_cachep
, GFP_KERNEL
);
729 c
->mfc_un
.res
.minvif
= MAXMIFS
;
730 mfc6_net_set(c
, net
);
734 static struct mfc6_cache
*ip6mr_cache_alloc_unres(struct net
*net
)
736 struct mfc6_cache
*c
= kmem_cache_zalloc(mrt_cachep
, GFP_ATOMIC
);
739 skb_queue_head_init(&c
->mfc_un
.unres
.unresolved
);
740 c
->mfc_un
.unres
.expires
= jiffies
+ 10 * HZ
;
741 mfc6_net_set(c
, net
);
746 * A cache entry has gone into a resolved state from queued
749 static void ip6mr_cache_resolve(struct mfc6_cache
*uc
, struct mfc6_cache
*c
)
754 * Play the pending entries through our router
757 while((skb
= __skb_dequeue(&uc
->mfc_un
.unres
.unresolved
))) {
758 if (ipv6_hdr(skb
)->version
== 0) {
760 struct nlmsghdr
*nlh
= (struct nlmsghdr
*)skb_pull(skb
, sizeof(struct ipv6hdr
));
762 if (ip6mr_fill_mroute(skb
, c
, NLMSG_DATA(nlh
)) > 0) {
763 nlh
->nlmsg_len
= skb_tail_pointer(skb
) - (u8
*)nlh
;
765 nlh
->nlmsg_type
= NLMSG_ERROR
;
766 nlh
->nlmsg_len
= NLMSG_LENGTH(sizeof(struct nlmsgerr
));
767 skb_trim(skb
, nlh
->nlmsg_len
);
768 ((struct nlmsgerr
*)NLMSG_DATA(nlh
))->error
= -EMSGSIZE
;
770 err
= rtnl_unicast(skb
, mfc6_net(uc
), NETLINK_CB(skb
).pid
);
772 ip6_mr_forward(skb
, c
);
777 * Bounce a cache query up to pim6sd. We could use netlink for this but pim6sd
778 * expects the following bizarre scheme.
780 * Called under mrt_lock.
783 static int ip6mr_cache_report(struct net
*net
, struct sk_buff
*pkt
, mifi_t mifi
,
790 #ifdef CONFIG_IPV6_PIMSM_V2
791 if (assert == MRT6MSG_WHOLEPKT
)
792 skb
= skb_realloc_headroom(pkt
, -skb_network_offset(pkt
)
796 skb
= alloc_skb(sizeof(struct ipv6hdr
) + sizeof(*msg
), GFP_ATOMIC
);
801 /* I suppose that internal messages
802 * do not require checksums */
804 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
806 #ifdef CONFIG_IPV6_PIMSM_V2
807 if (assert == MRT6MSG_WHOLEPKT
) {
808 /* Ugly, but we have no choice with this interface.
809 Duplicate old header, fix length etc.
810 And all this only to mangle msg->im6_msgtype and
811 to set msg->im6_mbz to "mbz" :-)
813 skb_push(skb
, -skb_network_offset(pkt
));
815 skb_push(skb
, sizeof(*msg
));
816 skb_reset_transport_header(skb
);
817 msg
= (struct mrt6msg
*)skb_transport_header(skb
);
819 msg
->im6_msgtype
= MRT6MSG_WHOLEPKT
;
820 msg
->im6_mif
= net
->ipv6
.mroute_reg_vif_num
;
822 ipv6_addr_copy(&msg
->im6_src
, &ipv6_hdr(pkt
)->saddr
);
823 ipv6_addr_copy(&msg
->im6_dst
, &ipv6_hdr(pkt
)->daddr
);
825 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
833 skb_put(skb
, sizeof(struct ipv6hdr
));
834 skb_reset_network_header(skb
);
835 skb_copy_to_linear_data(skb
, ipv6_hdr(pkt
), sizeof(struct ipv6hdr
));
840 skb_put(skb
, sizeof(*msg
));
841 skb_reset_transport_header(skb
);
842 msg
= (struct mrt6msg
*)skb_transport_header(skb
);
845 msg
->im6_msgtype
= assert;
848 ipv6_addr_copy(&msg
->im6_src
, &ipv6_hdr(pkt
)->saddr
);
849 ipv6_addr_copy(&msg
->im6_dst
, &ipv6_hdr(pkt
)->daddr
);
851 skb_dst_set(skb
, dst_clone(skb_dst(pkt
)));
852 skb
->ip_summed
= CHECKSUM_UNNECESSARY
;
855 if (net
->ipv6
.mroute6_sk
== NULL
) {
861 * Deliver to user space multicast routing algorithms
863 ret
= sock_queue_rcv_skb(net
->ipv6
.mroute6_sk
, skb
);
866 printk(KERN_WARNING
"mroute6: pending queue full, dropping entries.\n");
874 * Queue a packet for resolution. It gets locked cache entry!
878 ip6mr_cache_unresolved(struct net
*net
, mifi_t mifi
, struct sk_buff
*skb
)
881 struct mfc6_cache
*c
;
883 spin_lock_bh(&mfc_unres_lock
);
884 for (c
= mfc_unres_queue
; c
; c
= c
->next
) {
885 if (net_eq(mfc6_net(c
), net
) &&
886 ipv6_addr_equal(&c
->mf6c_mcastgrp
, &ipv6_hdr(skb
)->daddr
) &&
887 ipv6_addr_equal(&c
->mf6c_origin
, &ipv6_hdr(skb
)->saddr
))
893 * Create a new entry if allowable
896 if (atomic_read(&net
->ipv6
.cache_resolve_queue_len
) >= 10 ||
897 (c
= ip6mr_cache_alloc_unres(net
)) == NULL
) {
898 spin_unlock_bh(&mfc_unres_lock
);
905 * Fill in the new cache entry
908 c
->mf6c_origin
= ipv6_hdr(skb
)->saddr
;
909 c
->mf6c_mcastgrp
= ipv6_hdr(skb
)->daddr
;
912 * Reflect first query at pim6sd
914 err
= ip6mr_cache_report(net
, skb
, mifi
, MRT6MSG_NOCACHE
);
916 /* If the report failed throw the cache entry
919 spin_unlock_bh(&mfc_unres_lock
);
926 atomic_inc(&net
->ipv6
.cache_resolve_queue_len
);
927 c
->next
= mfc_unres_queue
;
930 ipmr_do_expire_process(1);
934 * See if we can append the packet
936 if (c
->mfc_un
.unres
.unresolved
.qlen
> 3) {
940 skb_queue_tail(&c
->mfc_un
.unres
.unresolved
, skb
);
944 spin_unlock_bh(&mfc_unres_lock
);
949 * MFC6 cache manipulation by user space
952 static int ip6mr_mfc_delete(struct net
*net
, struct mf6cctl
*mfc
)
955 struct mfc6_cache
*c
, **cp
;
957 line
= MFC6_HASH(&mfc
->mf6cc_mcastgrp
.sin6_addr
, &mfc
->mf6cc_origin
.sin6_addr
);
959 for (cp
= &net
->ipv6
.mfc6_cache_array
[line
];
960 (c
= *cp
) != NULL
; cp
= &c
->next
) {
961 if (ipv6_addr_equal(&c
->mf6c_origin
, &mfc
->mf6cc_origin
.sin6_addr
) &&
962 ipv6_addr_equal(&c
->mf6c_mcastgrp
, &mfc
->mf6cc_mcastgrp
.sin6_addr
)) {
963 write_lock_bh(&mrt_lock
);
965 write_unlock_bh(&mrt_lock
);
974 static int ip6mr_device_event(struct notifier_block
*this,
975 unsigned long event
, void *ptr
)
977 struct net_device
*dev
= ptr
;
978 struct net
*net
= dev_net(dev
);
979 struct mif_device
*v
;
982 if (event
!= NETDEV_UNREGISTER
)
985 v
= &net
->ipv6
.vif6_table
[0];
986 for (ct
= 0; ct
< net
->ipv6
.maxvif
; ct
++, v
++) {
988 mif6_delete(net
, ct
);
993 static struct notifier_block ip6_mr_notifier
= {
994 .notifier_call
= ip6mr_device_event
998 * Setup for IP multicast routing
1001 static int __net_init
ip6mr_net_init(struct net
*net
)
1004 net
->ipv6
.vif6_table
= kcalloc(MAXMIFS
, sizeof(struct mif_device
),
1006 if (!net
->ipv6
.vif6_table
) {
1011 /* Forwarding cache */
1012 net
->ipv6
.mfc6_cache_array
= kcalloc(MFC6_LINES
,
1013 sizeof(struct mfc6_cache
*),
1015 if (!net
->ipv6
.mfc6_cache_array
) {
1017 goto fail_mfc6_cache
;
1020 #ifdef CONFIG_IPV6_PIMSM_V2
1021 net
->ipv6
.mroute_reg_vif_num
= -1;
1024 #ifdef CONFIG_PROC_FS
1026 if (!proc_net_fops_create(net
, "ip6_mr_vif", 0, &ip6mr_vif_fops
))
1028 if (!proc_net_fops_create(net
, "ip6_mr_cache", 0, &ip6mr_mfc_fops
))
1029 goto proc_cache_fail
;
1033 #ifdef CONFIG_PROC_FS
1035 proc_net_remove(net
, "ip6_mr_vif");
1037 kfree(net
->ipv6
.mfc6_cache_array
);
1040 kfree(net
->ipv6
.vif6_table
);
1045 static void __net_exit
ip6mr_net_exit(struct net
*net
)
1047 #ifdef CONFIG_PROC_FS
1048 proc_net_remove(net
, "ip6_mr_cache");
1049 proc_net_remove(net
, "ip6_mr_vif");
1051 mroute_clean_tables(net
);
1052 kfree(net
->ipv6
.mfc6_cache_array
);
1053 kfree(net
->ipv6
.vif6_table
);
1056 static struct pernet_operations ip6mr_net_ops
= {
1057 .init
= ip6mr_net_init
,
1058 .exit
= ip6mr_net_exit
,
1061 int __init
ip6_mr_init(void)
1065 mrt_cachep
= kmem_cache_create("ip6_mrt_cache",
1066 sizeof(struct mfc6_cache
),
1067 0, SLAB_HWCACHE_ALIGN
,
1072 err
= register_pernet_subsys(&ip6mr_net_ops
);
1074 goto reg_pernet_fail
;
1076 setup_timer(&ipmr_expire_timer
, ipmr_expire_process
, 0);
1077 err
= register_netdevice_notifier(&ip6_mr_notifier
);
1079 goto reg_notif_fail
;
1082 del_timer(&ipmr_expire_timer
);
1083 unregister_pernet_subsys(&ip6mr_net_ops
);
1085 kmem_cache_destroy(mrt_cachep
);
1089 void ip6_mr_cleanup(void)
1091 unregister_netdevice_notifier(&ip6_mr_notifier
);
1092 del_timer(&ipmr_expire_timer
);
1093 unregister_pernet_subsys(&ip6mr_net_ops
);
1094 kmem_cache_destroy(mrt_cachep
);
1097 static int ip6mr_mfc_add(struct net
*net
, struct mf6cctl
*mfc
, int mrtsock
)
1100 struct mfc6_cache
*uc
, *c
, **cp
;
1101 unsigned char ttls
[MAXMIFS
];
1104 memset(ttls
, 255, MAXMIFS
);
1105 for (i
= 0; i
< MAXMIFS
; i
++) {
1106 if (IF_ISSET(i
, &mfc
->mf6cc_ifset
))
1111 line
= MFC6_HASH(&mfc
->mf6cc_mcastgrp
.sin6_addr
, &mfc
->mf6cc_origin
.sin6_addr
);
1113 for (cp
= &net
->ipv6
.mfc6_cache_array
[line
];
1114 (c
= *cp
) != NULL
; cp
= &c
->next
) {
1115 if (ipv6_addr_equal(&c
->mf6c_origin
, &mfc
->mf6cc_origin
.sin6_addr
) &&
1116 ipv6_addr_equal(&c
->mf6c_mcastgrp
, &mfc
->mf6cc_mcastgrp
.sin6_addr
))
1121 write_lock_bh(&mrt_lock
);
1122 c
->mf6c_parent
= mfc
->mf6cc_parent
;
1123 ip6mr_update_thresholds(c
, ttls
);
1125 c
->mfc_flags
|= MFC_STATIC
;
1126 write_unlock_bh(&mrt_lock
);
1130 if (!ipv6_addr_is_multicast(&mfc
->mf6cc_mcastgrp
.sin6_addr
))
1133 c
= ip6mr_cache_alloc(net
);
1137 c
->mf6c_origin
= mfc
->mf6cc_origin
.sin6_addr
;
1138 c
->mf6c_mcastgrp
= mfc
->mf6cc_mcastgrp
.sin6_addr
;
1139 c
->mf6c_parent
= mfc
->mf6cc_parent
;
1140 ip6mr_update_thresholds(c
, ttls
);
1142 c
->mfc_flags
|= MFC_STATIC
;
1144 write_lock_bh(&mrt_lock
);
1145 c
->next
= net
->ipv6
.mfc6_cache_array
[line
];
1146 net
->ipv6
.mfc6_cache_array
[line
] = c
;
1147 write_unlock_bh(&mrt_lock
);
1150 * Check to see if we resolved a queued list. If so we
1151 * need to send on the frames and tidy up.
1153 spin_lock_bh(&mfc_unres_lock
);
1154 for (cp
= &mfc_unres_queue
; (uc
= *cp
) != NULL
;
1156 if (net_eq(mfc6_net(uc
), net
) &&
1157 ipv6_addr_equal(&uc
->mf6c_origin
, &c
->mf6c_origin
) &&
1158 ipv6_addr_equal(&uc
->mf6c_mcastgrp
, &c
->mf6c_mcastgrp
)) {
1160 atomic_dec(&net
->ipv6
.cache_resolve_queue_len
);
1164 if (mfc_unres_queue
== NULL
)
1165 del_timer(&ipmr_expire_timer
);
1166 spin_unlock_bh(&mfc_unres_lock
);
1169 ip6mr_cache_resolve(uc
, c
);
1170 ip6mr_cache_free(uc
);
1176 * Close the multicast socket, and clear the vif tables etc
1179 static void mroute_clean_tables(struct net
*net
)
1184 * Shut down all active vif entries
1186 for (i
= 0; i
< net
->ipv6
.maxvif
; i
++) {
1187 if (!(net
->ipv6
.vif6_table
[i
].flags
& VIFF_STATIC
))
1188 mif6_delete(net
, i
);
1194 for (i
= 0; i
< MFC6_LINES
; i
++) {
1195 struct mfc6_cache
*c
, **cp
;
1197 cp
= &net
->ipv6
.mfc6_cache_array
[i
];
1198 while ((c
= *cp
) != NULL
) {
1199 if (c
->mfc_flags
& MFC_STATIC
) {
1203 write_lock_bh(&mrt_lock
);
1205 write_unlock_bh(&mrt_lock
);
1207 ip6mr_cache_free(c
);
1211 if (atomic_read(&net
->ipv6
.cache_resolve_queue_len
) != 0) {
1212 struct mfc6_cache
*c
, **cp
;
1214 spin_lock_bh(&mfc_unres_lock
);
1215 cp
= &mfc_unres_queue
;
1216 while ((c
= *cp
) != NULL
) {
1217 if (!net_eq(mfc6_net(c
), net
)) {
1222 ip6mr_destroy_unres(c
);
1224 spin_unlock_bh(&mfc_unres_lock
);
1228 static int ip6mr_sk_init(struct sock
*sk
)
1231 struct net
*net
= sock_net(sk
);
1234 write_lock_bh(&mrt_lock
);
1235 if (likely(net
->ipv6
.mroute6_sk
== NULL
)) {
1236 net
->ipv6
.mroute6_sk
= sk
;
1237 net
->ipv6
.devconf_all
->mc_forwarding
++;
1241 write_unlock_bh(&mrt_lock
);
1248 int ip6mr_sk_done(struct sock
*sk
)
1251 struct net
*net
= sock_net(sk
);
1254 if (sk
== net
->ipv6
.mroute6_sk
) {
1255 write_lock_bh(&mrt_lock
);
1256 net
->ipv6
.mroute6_sk
= NULL
;
1257 net
->ipv6
.devconf_all
->mc_forwarding
--;
1258 write_unlock_bh(&mrt_lock
);
1260 mroute_clean_tables(net
);
1269 * Socket options and virtual interface manipulation. The whole
1270 * virtual interface system is a complete heap, but unfortunately
1271 * that's how BSD mrouted happens to think. Maybe one day with a proper
1272 * MOSPF/PIM router set up we can clean this up.
1275 int ip6_mroute_setsockopt(struct sock
*sk
, int optname
, char __user
*optval
, int optlen
)
1281 struct net
*net
= sock_net(sk
);
1283 if (optname
!= MRT6_INIT
) {
1284 if (sk
!= net
->ipv6
.mroute6_sk
&& !capable(CAP_NET_ADMIN
))
1290 if (sk
->sk_type
!= SOCK_RAW
||
1291 inet_sk(sk
)->num
!= IPPROTO_ICMPV6
)
1293 if (optlen
< sizeof(int))
1296 return ip6mr_sk_init(sk
);
1299 return ip6mr_sk_done(sk
);
1302 if (optlen
< sizeof(vif
))
1304 if (copy_from_user(&vif
, optval
, sizeof(vif
)))
1306 if (vif
.mif6c_mifi
>= MAXMIFS
)
1309 ret
= mif6_add(net
, &vif
, sk
== net
->ipv6
.mroute6_sk
);
1314 if (optlen
< sizeof(mifi_t
))
1316 if (copy_from_user(&mifi
, optval
, sizeof(mifi_t
)))
1319 ret
= mif6_delete(net
, mifi
);
1324 * Manipulate the forwarding caches. These live
1325 * in a sort of kernel/user symbiosis.
1329 if (optlen
< sizeof(mfc
))
1331 if (copy_from_user(&mfc
, optval
, sizeof(mfc
)))
1334 if (optname
== MRT6_DEL_MFC
)
1335 ret
= ip6mr_mfc_delete(net
, &mfc
);
1337 ret
= ip6mr_mfc_add(net
, &mfc
,
1338 sk
== net
->ipv6
.mroute6_sk
);
1343 * Control PIM assert (to activate pim will activate assert)
1348 if (get_user(v
, (int __user
*)optval
))
1350 net
->ipv6
.mroute_do_assert
= !!v
;
1354 #ifdef CONFIG_IPV6_PIMSM_V2
1358 if (get_user(v
, (int __user
*)optval
))
1363 if (v
!= net
->ipv6
.mroute_do_pim
) {
1364 net
->ipv6
.mroute_do_pim
= v
;
1365 net
->ipv6
.mroute_do_assert
= v
;
1366 if (net
->ipv6
.mroute_do_pim
)
1367 ret
= inet6_add_protocol(&pim6_protocol
,
1370 ret
= inet6_del_protocol(&pim6_protocol
,
1381 * Spurious command, or MRT6_VERSION which you cannot
1385 return -ENOPROTOOPT
;
1390 * Getsock opt support for the multicast routing system.
1393 int ip6_mroute_getsockopt(struct sock
*sk
, int optname
, char __user
*optval
,
1398 struct net
*net
= sock_net(sk
);
1404 #ifdef CONFIG_IPV6_PIMSM_V2
1406 val
= net
->ipv6
.mroute_do_pim
;
1410 val
= net
->ipv6
.mroute_do_assert
;
1413 return -ENOPROTOOPT
;
1416 if (get_user(olr
, optlen
))
1419 olr
= min_t(int, olr
, sizeof(int));
1423 if (put_user(olr
, optlen
))
1425 if (copy_to_user(optval
, &val
, olr
))
1431 * The IP multicast ioctl support routines.
1434 int ip6mr_ioctl(struct sock
*sk
, int cmd
, void __user
*arg
)
1436 struct sioc_sg_req6 sr
;
1437 struct sioc_mif_req6 vr
;
1438 struct mif_device
*vif
;
1439 struct mfc6_cache
*c
;
1440 struct net
*net
= sock_net(sk
);
1443 case SIOCGETMIFCNT_IN6
:
1444 if (copy_from_user(&vr
, arg
, sizeof(vr
)))
1446 if (vr
.mifi
>= net
->ipv6
.maxvif
)
1448 read_lock(&mrt_lock
);
1449 vif
= &net
->ipv6
.vif6_table
[vr
.mifi
];
1450 if (MIF_EXISTS(net
, vr
.mifi
)) {
1451 vr
.icount
= vif
->pkt_in
;
1452 vr
.ocount
= vif
->pkt_out
;
1453 vr
.ibytes
= vif
->bytes_in
;
1454 vr
.obytes
= vif
->bytes_out
;
1455 read_unlock(&mrt_lock
);
1457 if (copy_to_user(arg
, &vr
, sizeof(vr
)))
1461 read_unlock(&mrt_lock
);
1462 return -EADDRNOTAVAIL
;
1463 case SIOCGETSGCNT_IN6
:
1464 if (copy_from_user(&sr
, arg
, sizeof(sr
)))
1467 read_lock(&mrt_lock
);
1468 c
= ip6mr_cache_find(net
, &sr
.src
.sin6_addr
, &sr
.grp
.sin6_addr
);
1470 sr
.pktcnt
= c
->mfc_un
.res
.pkt
;
1471 sr
.bytecnt
= c
->mfc_un
.res
.bytes
;
1472 sr
.wrong_if
= c
->mfc_un
.res
.wrong_if
;
1473 read_unlock(&mrt_lock
);
1475 if (copy_to_user(arg
, &sr
, sizeof(sr
)))
1479 read_unlock(&mrt_lock
);
1480 return -EADDRNOTAVAIL
;
1482 return -ENOIOCTLCMD
;
1487 static inline int ip6mr_forward2_finish(struct sk_buff
*skb
)
1489 IP6_INC_STATS_BH(dev_net(skb_dst(skb
)->dev
), ip6_dst_idev(skb_dst(skb
)),
1490 IPSTATS_MIB_OUTFORWDATAGRAMS
);
1491 return dst_output(skb
);
1495 * Processing handlers for ip6mr_forward
1498 static int ip6mr_forward2(struct sk_buff
*skb
, struct mfc6_cache
*c
, int vifi
)
1500 struct ipv6hdr
*ipv6h
;
1501 struct net
*net
= mfc6_net(c
);
1502 struct mif_device
*vif
= &net
->ipv6
.vif6_table
[vifi
];
1503 struct net_device
*dev
;
1504 struct dst_entry
*dst
;
1507 if (vif
->dev
== NULL
)
1510 #ifdef CONFIG_IPV6_PIMSM_V2
1511 if (vif
->flags
& MIFF_REGISTER
) {
1513 vif
->bytes_out
+= skb
->len
;
1514 vif
->dev
->stats
.tx_bytes
+= skb
->len
;
1515 vif
->dev
->stats
.tx_packets
++;
1516 ip6mr_cache_report(net
, skb
, vifi
, MRT6MSG_WHOLEPKT
);
1521 ipv6h
= ipv6_hdr(skb
);
1523 fl
= (struct flowi
) {
1526 { .daddr
= ipv6h
->daddr
, }
1530 dst
= ip6_route_output(net
, NULL
, &fl
);
1535 skb_dst_set(skb
, dst
);
1538 * RFC1584 teaches, that DVMRP/PIM router must deliver packets locally
1539 * not only before forwarding, but after forwarding on all output
1540 * interfaces. It is clear, if mrouter runs a multicasting
1541 * program, it should receive packets not depending to what interface
1542 * program is joined.
1543 * If we will not make it, the program will have to join on all
1544 * interfaces. On the other hand, multihoming host (or router, but
1545 * not mrouter) cannot join to more than one interface - it will
1546 * result in receiving multiple packets.
1551 vif
->bytes_out
+= skb
->len
;
1553 /* We are about to write */
1554 /* XXX: extension headers? */
1555 if (skb_cow(skb
, sizeof(*ipv6h
) + LL_RESERVED_SPACE(dev
)))
1558 ipv6h
= ipv6_hdr(skb
);
1561 IP6CB(skb
)->flags
|= IP6SKB_FORWARDED
;
1563 return NF_HOOK(PF_INET6
, NF_INET_FORWARD
, skb
, skb
->dev
, dev
,
1564 ip6mr_forward2_finish
);
1571 static int ip6mr_find_vif(struct net_device
*dev
)
1573 struct net
*net
= dev_net(dev
);
1575 for (ct
= net
->ipv6
.maxvif
- 1; ct
>= 0; ct
--) {
1576 if (net
->ipv6
.vif6_table
[ct
].dev
== dev
)
1582 static int ip6_mr_forward(struct sk_buff
*skb
, struct mfc6_cache
*cache
)
1586 struct net
*net
= mfc6_net(cache
);
1588 vif
= cache
->mf6c_parent
;
1589 cache
->mfc_un
.res
.pkt
++;
1590 cache
->mfc_un
.res
.bytes
+= skb
->len
;
1593 * Wrong interface: drop packet and (maybe) send PIM assert.
1595 if (net
->ipv6
.vif6_table
[vif
].dev
!= skb
->dev
) {
1598 cache
->mfc_un
.res
.wrong_if
++;
1599 true_vifi
= ip6mr_find_vif(skb
->dev
);
1601 if (true_vifi
>= 0 && net
->ipv6
.mroute_do_assert
&&
1602 /* pimsm uses asserts, when switching from RPT to SPT,
1603 so that we cannot check that packet arrived on an oif.
1604 It is bad, but otherwise we would need to move pretty
1605 large chunk of pimd to kernel. Ough... --ANK
1607 (net
->ipv6
.mroute_do_pim
||
1608 cache
->mfc_un
.res
.ttls
[true_vifi
] < 255) &&
1610 cache
->mfc_un
.res
.last_assert
+ MFC_ASSERT_THRESH
)) {
1611 cache
->mfc_un
.res
.last_assert
= jiffies
;
1612 ip6mr_cache_report(net
, skb
, true_vifi
, MRT6MSG_WRONGMIF
);
1617 net
->ipv6
.vif6_table
[vif
].pkt_in
++;
1618 net
->ipv6
.vif6_table
[vif
].bytes_in
+= skb
->len
;
1623 for (ct
= cache
->mfc_un
.res
.maxvif
- 1; ct
>= cache
->mfc_un
.res
.minvif
; ct
--) {
1624 if (ipv6_hdr(skb
)->hop_limit
> cache
->mfc_un
.res
.ttls
[ct
]) {
1626 struct sk_buff
*skb2
= skb_clone(skb
, GFP_ATOMIC
);
1628 ip6mr_forward2(skb2
, cache
, psend
);
1634 ip6mr_forward2(skb
, cache
, psend
);
1645 * Multicast packets for forwarding arrive here
1648 int ip6_mr_input(struct sk_buff
*skb
)
1650 struct mfc6_cache
*cache
;
1651 struct net
*net
= dev_net(skb
->dev
);
1653 read_lock(&mrt_lock
);
1654 cache
= ip6mr_cache_find(net
,
1655 &ipv6_hdr(skb
)->saddr
, &ipv6_hdr(skb
)->daddr
);
1658 * No usable cache entry
1660 if (cache
== NULL
) {
1663 vif
= ip6mr_find_vif(skb
->dev
);
1665 int err
= ip6mr_cache_unresolved(net
, vif
, skb
);
1666 read_unlock(&mrt_lock
);
1670 read_unlock(&mrt_lock
);
1675 ip6_mr_forward(skb
, cache
);
1677 read_unlock(&mrt_lock
);
1684 ip6mr_fill_mroute(struct sk_buff
*skb
, struct mfc6_cache
*c
, struct rtmsg
*rtm
)
1687 struct rtnexthop
*nhp
;
1688 struct net
*net
= mfc6_net(c
);
1689 struct net_device
*dev
= net
->ipv6
.vif6_table
[c
->mf6c_parent
].dev
;
1690 u8
*b
= skb_tail_pointer(skb
);
1691 struct rtattr
*mp_head
;
1694 RTA_PUT(skb
, RTA_IIF
, 4, &dev
->ifindex
);
1696 mp_head
= (struct rtattr
*)skb_put(skb
, RTA_LENGTH(0));
1698 for (ct
= c
->mfc_un
.res
.minvif
; ct
< c
->mfc_un
.res
.maxvif
; ct
++) {
1699 if (c
->mfc_un
.res
.ttls
[ct
] < 255) {
1700 if (skb_tailroom(skb
) < RTA_ALIGN(RTA_ALIGN(sizeof(*nhp
)) + 4))
1701 goto rtattr_failure
;
1702 nhp
= (struct rtnexthop
*)skb_put(skb
, RTA_ALIGN(sizeof(*nhp
)));
1703 nhp
->rtnh_flags
= 0;
1704 nhp
->rtnh_hops
= c
->mfc_un
.res
.ttls
[ct
];
1705 nhp
->rtnh_ifindex
= net
->ipv6
.vif6_table
[ct
].dev
->ifindex
;
1706 nhp
->rtnh_len
= sizeof(*nhp
);
1709 mp_head
->rta_type
= RTA_MULTIPATH
;
1710 mp_head
->rta_len
= skb_tail_pointer(skb
) - (u8
*)mp_head
;
1711 rtm
->rtm_type
= RTN_MULTICAST
;
1719 int ip6mr_get_route(struct net
*net
,
1720 struct sk_buff
*skb
, struct rtmsg
*rtm
, int nowait
)
1723 struct mfc6_cache
*cache
;
1724 struct rt6_info
*rt
= (struct rt6_info
*)skb_dst(skb
);
1726 read_lock(&mrt_lock
);
1727 cache
= ip6mr_cache_find(net
, &rt
->rt6i_src
.addr
, &rt
->rt6i_dst
.addr
);
1730 struct sk_buff
*skb2
;
1731 struct ipv6hdr
*iph
;
1732 struct net_device
*dev
;
1736 read_unlock(&mrt_lock
);
1741 if (dev
== NULL
|| (vif
= ip6mr_find_vif(dev
)) < 0) {
1742 read_unlock(&mrt_lock
);
1746 /* really correct? */
1747 skb2
= alloc_skb(sizeof(struct ipv6hdr
), GFP_ATOMIC
);
1749 read_unlock(&mrt_lock
);
1753 skb_reset_transport_header(skb2
);
1755 skb_put(skb2
, sizeof(struct ipv6hdr
));
1756 skb_reset_network_header(skb2
);
1758 iph
= ipv6_hdr(skb2
);
1761 iph
->flow_lbl
[0] = 0;
1762 iph
->flow_lbl
[1] = 0;
1763 iph
->flow_lbl
[2] = 0;
1764 iph
->payload_len
= 0;
1765 iph
->nexthdr
= IPPROTO_NONE
;
1767 ipv6_addr_copy(&iph
->saddr
, &rt
->rt6i_src
.addr
);
1768 ipv6_addr_copy(&iph
->daddr
, &rt
->rt6i_dst
.addr
);
1770 err
= ip6mr_cache_unresolved(net
, vif
, skb2
);
1771 read_unlock(&mrt_lock
);
1776 if (!nowait
&& (rtm
->rtm_flags
&RTM_F_NOTIFY
))
1777 cache
->mfc_flags
|= MFC_NOTIFY
;
1779 err
= ip6mr_fill_mroute(skb
, cache
, rtm
);
1780 read_unlock(&mrt_lock
);