2 * IP multicast routing support for mrouted 3.6/3.8
4 * (c) 1995 Alan Cox, <alan@lxorguk.ukuu.org.uk>
5 * Linux Consultancy and Custom Driver Development
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
13 * Michael Chastain : Incorrect size of copying.
14 * Alan Cox : Added the cache manager code
15 * Alan Cox : Fixed the clone/copy bug and device race.
16 * Mike McLagan : Routing by source
17 * Malcolm Beattie : Buffer handling fixes.
18 * Alexey Kuznetsov : Double buffer free and other fixes.
19 * SVR Anand : Fixed several multicast bugs and problems.
20 * Alexey Kuznetsov : Status, optimisations and more.
21 * Brad Parker : Better behaviour on mrouted upcall
23 * Carlos Picoto : PIMv1 Support
24 * Pavlin Ivanov Radoslavov: PIMv2 Registers must checksum only PIM header
25 * Relax this requirement to work with older peers.
29 #include <linux/uaccess.h>
30 #include <linux/types.h>
31 #include <linux/cache.h>
32 #include <linux/capability.h>
33 #include <linux/errno.h>
35 #include <linux/kernel.h>
36 #include <linux/fcntl.h>
37 #include <linux/stat.h>
38 #include <linux/socket.h>
40 #include <linux/inet.h>
41 #include <linux/netdevice.h>
42 #include <linux/inetdevice.h>
43 #include <linux/igmp.h>
44 #include <linux/proc_fs.h>
45 #include <linux/seq_file.h>
46 #include <linux/mroute.h>
47 #include <linux/init.h>
48 #include <linux/if_ether.h>
49 #include <linux/slab.h>
50 #include <net/net_namespace.h>
52 #include <net/protocol.h>
53 #include <linux/skbuff.h>
54 #include <net/route.h>
58 #include <linux/notifier.h>
59 #include <linux/if_arp.h>
60 #include <linux/netfilter_ipv4.h>
61 #include <linux/compat.h>
62 #include <linux/export.h>
63 #include <linux/rhashtable.h>
64 #include <net/ip_tunnels.h>
65 #include <net/checksum.h>
66 #include <net/netlink.h>
67 #include <net/fib_rules.h>
68 #include <linux/netconf.h>
69 #include <net/nexthop.h>
70 #include <net/switchdev.h>
73 struct fib_rule common
;
80 /* Big lock, protecting vif table, mrt cache and mroute socket state.
81 * Note that the changes are semaphored via rtnl_lock.
84 static DEFINE_RWLOCK(mrt_lock
);
86 /* Multicast router control variables */
88 /* Special spinlock for queue of unresolved entries */
89 static DEFINE_SPINLOCK(mfc_unres_lock
);
91 /* We return to original Alan's scheme. Hash table of resolved
92 * entries is changed only in process context and protected
93 * with weak lock mrt_lock. Queue of unresolved entries is protected
94 * with strong spinlock mfc_unres_lock.
96 * In this case data path is free of exclusive locks at all.
99 static struct kmem_cache
*mrt_cachep __ro_after_init
;
101 static struct mr_table
*ipmr_new_table(struct net
*net
, u32 id
);
102 static void ipmr_free_table(struct mr_table
*mrt
);
104 static void ip_mr_forward(struct net
*net
, struct mr_table
*mrt
,
105 struct net_device
*dev
, struct sk_buff
*skb
,
106 struct mfc_cache
*cache
, int local
);
107 static int ipmr_cache_report(struct mr_table
*mrt
,
108 struct sk_buff
*pkt
, vifi_t vifi
, int assert);
109 static void mroute_netlink_event(struct mr_table
*mrt
, struct mfc_cache
*mfc
,
111 static void igmpmsg_netlink_event(struct mr_table
*mrt
, struct sk_buff
*pkt
);
112 static void mroute_clean_tables(struct mr_table
*mrt
, bool all
);
113 static void ipmr_expire_process(struct timer_list
*t
);
115 #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
116 #define ipmr_for_each_table(mrt, net) \
117 list_for_each_entry_rcu(mrt, &net->ipv4.mr_tables, list)
119 static struct mr_table
*ipmr_mr_table_iter(struct net
*net
,
120 struct mr_table
*mrt
)
122 struct mr_table
*ret
;
125 ret
= list_entry_rcu(net
->ipv4
.mr_tables
.next
,
126 struct mr_table
, list
);
128 ret
= list_entry_rcu(mrt
->list
.next
,
129 struct mr_table
, list
);
131 if (&ret
->list
== &net
->ipv4
.mr_tables
)
136 static struct mr_table
*ipmr_get_table(struct net
*net
, u32 id
)
138 struct mr_table
*mrt
;
140 ipmr_for_each_table(mrt
, net
) {
147 static int ipmr_fib_lookup(struct net
*net
, struct flowi4
*flp4
,
148 struct mr_table
**mrt
)
151 struct ipmr_result res
;
152 struct fib_lookup_arg arg
= {
154 .flags
= FIB_LOOKUP_NOREF
,
157 /* update flow if oif or iif point to device enslaved to l3mdev */
158 l3mdev_update_flow(net
, flowi4_to_flowi(flp4
));
160 err
= fib_rules_lookup(net
->ipv4
.mr_rules_ops
,
161 flowi4_to_flowi(flp4
), 0, &arg
);
168 static int ipmr_rule_action(struct fib_rule
*rule
, struct flowi
*flp
,
169 int flags
, struct fib_lookup_arg
*arg
)
171 struct ipmr_result
*res
= arg
->result
;
172 struct mr_table
*mrt
;
174 switch (rule
->action
) {
177 case FR_ACT_UNREACHABLE
:
179 case FR_ACT_PROHIBIT
:
181 case FR_ACT_BLACKHOLE
:
186 arg
->table
= fib_rule_get_table(rule
, arg
);
188 mrt
= ipmr_get_table(rule
->fr_net
, arg
->table
);
195 static int ipmr_rule_match(struct fib_rule
*rule
, struct flowi
*fl
, int flags
)
200 static const struct nla_policy ipmr_rule_policy
[FRA_MAX
+ 1] = {
204 static int ipmr_rule_configure(struct fib_rule
*rule
, struct sk_buff
*skb
,
205 struct fib_rule_hdr
*frh
, struct nlattr
**tb
,
206 struct netlink_ext_ack
*extack
)
211 static int ipmr_rule_compare(struct fib_rule
*rule
, struct fib_rule_hdr
*frh
,
217 static int ipmr_rule_fill(struct fib_rule
*rule
, struct sk_buff
*skb
,
218 struct fib_rule_hdr
*frh
)
226 static const struct fib_rules_ops __net_initconst ipmr_rules_ops_template
= {
227 .family
= RTNL_FAMILY_IPMR
,
228 .rule_size
= sizeof(struct ipmr_rule
),
229 .addr_size
= sizeof(u32
),
230 .action
= ipmr_rule_action
,
231 .match
= ipmr_rule_match
,
232 .configure
= ipmr_rule_configure
,
233 .compare
= ipmr_rule_compare
,
234 .fill
= ipmr_rule_fill
,
235 .nlgroup
= RTNLGRP_IPV4_RULE
,
236 .policy
= ipmr_rule_policy
,
237 .owner
= THIS_MODULE
,
240 static int __net_init
ipmr_rules_init(struct net
*net
)
242 struct fib_rules_ops
*ops
;
243 struct mr_table
*mrt
;
246 ops
= fib_rules_register(&ipmr_rules_ops_template
, net
);
250 INIT_LIST_HEAD(&net
->ipv4
.mr_tables
);
252 mrt
= ipmr_new_table(net
, RT_TABLE_DEFAULT
);
258 err
= fib_default_rule_add(ops
, 0x7fff, RT_TABLE_DEFAULT
, 0);
262 net
->ipv4
.mr_rules_ops
= ops
;
266 ipmr_free_table(mrt
);
268 fib_rules_unregister(ops
);
272 static void __net_exit
ipmr_rules_exit(struct net
*net
)
274 struct mr_table
*mrt
, *next
;
277 list_for_each_entry_safe(mrt
, next
, &net
->ipv4
.mr_tables
, list
) {
278 list_del(&mrt
->list
);
279 ipmr_free_table(mrt
);
281 fib_rules_unregister(net
->ipv4
.mr_rules_ops
);
285 static int ipmr_rules_dump(struct net
*net
, struct notifier_block
*nb
)
287 return fib_rules_dump(net
, nb
, RTNL_FAMILY_IPMR
);
290 static unsigned int ipmr_rules_seq_read(struct net
*net
)
292 return fib_rules_seq_read(net
, RTNL_FAMILY_IPMR
);
295 bool ipmr_rule_default(const struct fib_rule
*rule
)
297 return fib_rule_matchall(rule
) && rule
->table
== RT_TABLE_DEFAULT
;
299 EXPORT_SYMBOL(ipmr_rule_default
);
301 #define ipmr_for_each_table(mrt, net) \
302 for (mrt = net->ipv4.mrt; mrt; mrt = NULL)
304 static struct mr_table
*ipmr_mr_table_iter(struct net
*net
,
305 struct mr_table
*mrt
)
308 return net
->ipv4
.mrt
;
312 static struct mr_table
*ipmr_get_table(struct net
*net
, u32 id
)
314 return net
->ipv4
.mrt
;
317 static int ipmr_fib_lookup(struct net
*net
, struct flowi4
*flp4
,
318 struct mr_table
**mrt
)
320 *mrt
= net
->ipv4
.mrt
;
324 static int __net_init
ipmr_rules_init(struct net
*net
)
326 struct mr_table
*mrt
;
328 mrt
= ipmr_new_table(net
, RT_TABLE_DEFAULT
);
335 static void __net_exit
ipmr_rules_exit(struct net
*net
)
338 ipmr_free_table(net
->ipv4
.mrt
);
339 net
->ipv4
.mrt
= NULL
;
343 static int ipmr_rules_dump(struct net
*net
, struct notifier_block
*nb
)
348 static unsigned int ipmr_rules_seq_read(struct net
*net
)
353 bool ipmr_rule_default(const struct fib_rule
*rule
)
357 EXPORT_SYMBOL(ipmr_rule_default
);
360 static inline int ipmr_hash_cmp(struct rhashtable_compare_arg
*arg
,
363 const struct mfc_cache_cmp_arg
*cmparg
= arg
->key
;
364 struct mfc_cache
*c
= (struct mfc_cache
*)ptr
;
366 return cmparg
->mfc_mcastgrp
!= c
->mfc_mcastgrp
||
367 cmparg
->mfc_origin
!= c
->mfc_origin
;
370 static const struct rhashtable_params ipmr_rht_params
= {
371 .head_offset
= offsetof(struct mr_mfc
, mnode
),
372 .key_offset
= offsetof(struct mfc_cache
, cmparg
),
373 .key_len
= sizeof(struct mfc_cache_cmp_arg
),
376 .obj_cmpfn
= ipmr_hash_cmp
,
377 .automatic_shrinking
= true,
380 static void ipmr_new_table_set(struct mr_table
*mrt
,
383 #ifdef CONFIG_IP_MROUTE_MULTIPLE_TABLES
384 list_add_tail_rcu(&mrt
->list
, &net
->ipv4
.mr_tables
);
388 static struct mfc_cache_cmp_arg ipmr_mr_table_ops_cmparg_any
= {
389 .mfc_mcastgrp
= htonl(INADDR_ANY
),
390 .mfc_origin
= htonl(INADDR_ANY
),
393 static struct mr_table_ops ipmr_mr_table_ops
= {
394 .rht_params
= &ipmr_rht_params
,
395 .cmparg_any
= &ipmr_mr_table_ops_cmparg_any
,
398 static struct mr_table
*ipmr_new_table(struct net
*net
, u32 id
)
400 struct mr_table
*mrt
;
402 /* "pimreg%u" should not exceed 16 bytes (IFNAMSIZ) */
403 if (id
!= RT_TABLE_DEFAULT
&& id
>= 1000000000)
404 return ERR_PTR(-EINVAL
);
406 mrt
= ipmr_get_table(net
, id
);
410 return mr_table_alloc(net
, id
, &ipmr_mr_table_ops
,
411 ipmr_expire_process
, ipmr_new_table_set
);
414 static void ipmr_free_table(struct mr_table
*mrt
)
416 del_timer_sync(&mrt
->ipmr_expire_timer
);
417 mroute_clean_tables(mrt
, true);
418 rhltable_destroy(&mrt
->mfc_hash
);
422 /* Service routines creating virtual interfaces: DVMRP tunnels and PIMREG */
424 static void ipmr_del_tunnel(struct net_device
*dev
, struct vifctl
*v
)
426 struct net
*net
= dev_net(dev
);
430 dev
= __dev_get_by_name(net
, "tunl0");
432 const struct net_device_ops
*ops
= dev
->netdev_ops
;
434 struct ip_tunnel_parm p
;
436 memset(&p
, 0, sizeof(p
));
437 p
.iph
.daddr
= v
->vifc_rmt_addr
.s_addr
;
438 p
.iph
.saddr
= v
->vifc_lcl_addr
.s_addr
;
441 p
.iph
.protocol
= IPPROTO_IPIP
;
442 sprintf(p
.name
, "dvmrp%d", v
->vifc_vifi
);
443 ifr
.ifr_ifru
.ifru_data
= (__force
void __user
*)&p
;
445 if (ops
->ndo_do_ioctl
) {
446 mm_segment_t oldfs
= get_fs();
449 ops
->ndo_do_ioctl(dev
, &ifr
, SIOCDELTUNNEL
);
455 /* Initialize ipmr pimreg/tunnel in_device */
456 static bool ipmr_init_vif_indev(const struct net_device
*dev
)
458 struct in_device
*in_dev
;
462 in_dev
= __in_dev_get_rtnl(dev
);
465 ipv4_devconf_setall(in_dev
);
466 neigh_parms_data_state_setall(in_dev
->arp_parms
);
467 IPV4_DEVCONF(in_dev
->cnf
, RP_FILTER
) = 0;
472 static struct net_device
*ipmr_new_tunnel(struct net
*net
, struct vifctl
*v
)
474 struct net_device
*dev
;
476 dev
= __dev_get_by_name(net
, "tunl0");
479 const struct net_device_ops
*ops
= dev
->netdev_ops
;
482 struct ip_tunnel_parm p
;
484 memset(&p
, 0, sizeof(p
));
485 p
.iph
.daddr
= v
->vifc_rmt_addr
.s_addr
;
486 p
.iph
.saddr
= v
->vifc_lcl_addr
.s_addr
;
489 p
.iph
.protocol
= IPPROTO_IPIP
;
490 sprintf(p
.name
, "dvmrp%d", v
->vifc_vifi
);
491 ifr
.ifr_ifru
.ifru_data
= (__force
void __user
*)&p
;
493 if (ops
->ndo_do_ioctl
) {
494 mm_segment_t oldfs
= get_fs();
497 err
= ops
->ndo_do_ioctl(dev
, &ifr
, SIOCADDTUNNEL
);
505 (dev
= __dev_get_by_name(net
, p
.name
)) != NULL
) {
506 dev
->flags
|= IFF_MULTICAST
;
507 if (!ipmr_init_vif_indev(dev
))
517 unregister_netdevice(dev
);
521 #if defined(CONFIG_IP_PIMSM_V1) || defined(CONFIG_IP_PIMSM_V2)
522 static netdev_tx_t
reg_vif_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
524 struct net
*net
= dev_net(dev
);
525 struct mr_table
*mrt
;
526 struct flowi4 fl4
= {
527 .flowi4_oif
= dev
->ifindex
,
528 .flowi4_iif
= skb
->skb_iif
? : LOOPBACK_IFINDEX
,
529 .flowi4_mark
= skb
->mark
,
533 err
= ipmr_fib_lookup(net
, &fl4
, &mrt
);
539 read_lock(&mrt_lock
);
540 dev
->stats
.tx_bytes
+= skb
->len
;
541 dev
->stats
.tx_packets
++;
542 ipmr_cache_report(mrt
, skb
, mrt
->mroute_reg_vif_num
, IGMPMSG_WHOLEPKT
);
543 read_unlock(&mrt_lock
);
548 static int reg_vif_get_iflink(const struct net_device
*dev
)
553 static const struct net_device_ops reg_vif_netdev_ops
= {
554 .ndo_start_xmit
= reg_vif_xmit
,
555 .ndo_get_iflink
= reg_vif_get_iflink
,
558 static void reg_vif_setup(struct net_device
*dev
)
560 dev
->type
= ARPHRD_PIMREG
;
561 dev
->mtu
= ETH_DATA_LEN
- sizeof(struct iphdr
) - 8;
562 dev
->flags
= IFF_NOARP
;
563 dev
->netdev_ops
= ®_vif_netdev_ops
;
564 dev
->needs_free_netdev
= true;
565 dev
->features
|= NETIF_F_NETNS_LOCAL
;
568 static struct net_device
*ipmr_reg_vif(struct net
*net
, struct mr_table
*mrt
)
570 struct net_device
*dev
;
573 if (mrt
->id
== RT_TABLE_DEFAULT
)
574 sprintf(name
, "pimreg");
576 sprintf(name
, "pimreg%u", mrt
->id
);
578 dev
= alloc_netdev(0, name
, NET_NAME_UNKNOWN
, reg_vif_setup
);
583 dev_net_set(dev
, net
);
585 if (register_netdevice(dev
)) {
590 if (!ipmr_init_vif_indev(dev
))
600 unregister_netdevice(dev
);
604 /* called with rcu_read_lock() */
605 static int __pim_rcv(struct mr_table
*mrt
, struct sk_buff
*skb
,
608 struct net_device
*reg_dev
= NULL
;
611 encap
= (struct iphdr
*)(skb_transport_header(skb
) + pimlen
);
613 * a. packet is really sent to a multicast group
614 * b. packet is not a NULL-REGISTER
615 * c. packet is not truncated
617 if (!ipv4_is_multicast(encap
->daddr
) ||
618 encap
->tot_len
== 0 ||
619 ntohs(encap
->tot_len
) + pimlen
> skb
->len
)
622 read_lock(&mrt_lock
);
623 if (mrt
->mroute_reg_vif_num
>= 0)
624 reg_dev
= mrt
->vif_table
[mrt
->mroute_reg_vif_num
].dev
;
625 read_unlock(&mrt_lock
);
630 skb
->mac_header
= skb
->network_header
;
631 skb_pull(skb
, (u8
*)encap
- skb
->data
);
632 skb_reset_network_header(skb
);
633 skb
->protocol
= htons(ETH_P_IP
);
634 skb
->ip_summed
= CHECKSUM_NONE
;
636 skb_tunnel_rx(skb
, reg_dev
, dev_net(reg_dev
));
640 return NET_RX_SUCCESS
;
643 static struct net_device
*ipmr_reg_vif(struct net
*net
, struct mr_table
*mrt
)
649 static int call_ipmr_vif_entry_notifiers(struct net
*net
,
650 enum fib_event_type event_type
,
651 struct vif_device
*vif
,
652 vifi_t vif_index
, u32 tb_id
)
654 return mr_call_vif_notifiers(net
, RTNL_FAMILY_IPMR
, event_type
,
655 vif
, vif_index
, tb_id
,
656 &net
->ipv4
.ipmr_seq
);
659 static int call_ipmr_mfc_entry_notifiers(struct net
*net
,
660 enum fib_event_type event_type
,
661 struct mfc_cache
*mfc
, u32 tb_id
)
663 return mr_call_mfc_notifiers(net
, RTNL_FAMILY_IPMR
, event_type
,
664 &mfc
->_c
, tb_id
, &net
->ipv4
.ipmr_seq
);
668 * vif_delete - Delete a VIF entry
669 * @notify: Set to 1, if the caller is a notifier_call
671 static int vif_delete(struct mr_table
*mrt
, int vifi
, int notify
,
672 struct list_head
*head
)
674 struct net
*net
= read_pnet(&mrt
->net
);
675 struct vif_device
*v
;
676 struct net_device
*dev
;
677 struct in_device
*in_dev
;
679 if (vifi
< 0 || vifi
>= mrt
->maxvif
)
680 return -EADDRNOTAVAIL
;
682 v
= &mrt
->vif_table
[vifi
];
684 if (VIF_EXISTS(mrt
, vifi
))
685 call_ipmr_vif_entry_notifiers(net
, FIB_EVENT_VIF_DEL
, v
, vifi
,
688 write_lock_bh(&mrt_lock
);
693 write_unlock_bh(&mrt_lock
);
694 return -EADDRNOTAVAIL
;
697 if (vifi
== mrt
->mroute_reg_vif_num
)
698 mrt
->mroute_reg_vif_num
= -1;
700 if (vifi
+ 1 == mrt
->maxvif
) {
703 for (tmp
= vifi
- 1; tmp
>= 0; tmp
--) {
704 if (VIF_EXISTS(mrt
, tmp
))
710 write_unlock_bh(&mrt_lock
);
712 dev_set_allmulti(dev
, -1);
714 in_dev
= __in_dev_get_rtnl(dev
);
716 IPV4_DEVCONF(in_dev
->cnf
, MC_FORWARDING
)--;
717 inet_netconf_notify_devconf(dev_net(dev
), RTM_NEWNETCONF
,
718 NETCONFA_MC_FORWARDING
,
719 dev
->ifindex
, &in_dev
->cnf
);
720 ip_rt_multicast_event(in_dev
);
723 if (v
->flags
& (VIFF_TUNNEL
| VIFF_REGISTER
) && !notify
)
724 unregister_netdevice_queue(dev
, head
);
730 static void ipmr_cache_free_rcu(struct rcu_head
*head
)
732 struct mr_mfc
*c
= container_of(head
, struct mr_mfc
, rcu
);
734 kmem_cache_free(mrt_cachep
, (struct mfc_cache
*)c
);
737 static void ipmr_cache_free(struct mfc_cache
*c
)
739 call_rcu(&c
->_c
.rcu
, ipmr_cache_free_rcu
);
742 /* Destroy an unresolved cache entry, killing queued skbs
743 * and reporting error to netlink readers.
745 static void ipmr_destroy_unres(struct mr_table
*mrt
, struct mfc_cache
*c
)
747 struct net
*net
= read_pnet(&mrt
->net
);
751 atomic_dec(&mrt
->cache_resolve_queue_len
);
753 while ((skb
= skb_dequeue(&c
->_c
.mfc_un
.unres
.unresolved
))) {
754 if (ip_hdr(skb
)->version
== 0) {
755 struct nlmsghdr
*nlh
= skb_pull(skb
,
756 sizeof(struct iphdr
));
757 nlh
->nlmsg_type
= NLMSG_ERROR
;
758 nlh
->nlmsg_len
= nlmsg_msg_size(sizeof(struct nlmsgerr
));
759 skb_trim(skb
, nlh
->nlmsg_len
);
761 e
->error
= -ETIMEDOUT
;
762 memset(&e
->msg
, 0, sizeof(e
->msg
));
764 rtnl_unicast(skb
, net
, NETLINK_CB(skb
).portid
);
773 /* Timer process for the unresolved queue. */
774 static void ipmr_expire_process(struct timer_list
*t
)
776 struct mr_table
*mrt
= from_timer(mrt
, t
, ipmr_expire_timer
);
777 struct mr_mfc
*c
, *next
;
778 unsigned long expires
;
781 if (!spin_trylock(&mfc_unres_lock
)) {
782 mod_timer(&mrt
->ipmr_expire_timer
, jiffies
+HZ
/10);
786 if (list_empty(&mrt
->mfc_unres_queue
))
792 list_for_each_entry_safe(c
, next
, &mrt
->mfc_unres_queue
, list
) {
793 if (time_after(c
->mfc_un
.unres
.expires
, now
)) {
794 unsigned long interval
= c
->mfc_un
.unres
.expires
- now
;
795 if (interval
< expires
)
801 mroute_netlink_event(mrt
, (struct mfc_cache
*)c
, RTM_DELROUTE
);
802 ipmr_destroy_unres(mrt
, (struct mfc_cache
*)c
);
805 if (!list_empty(&mrt
->mfc_unres_queue
))
806 mod_timer(&mrt
->ipmr_expire_timer
, jiffies
+ expires
);
809 spin_unlock(&mfc_unres_lock
);
812 /* Fill oifs list. It is called under write locked mrt_lock. */
813 static void ipmr_update_thresholds(struct mr_table
*mrt
, struct mr_mfc
*cache
,
818 cache
->mfc_un
.res
.minvif
= MAXVIFS
;
819 cache
->mfc_un
.res
.maxvif
= 0;
820 memset(cache
->mfc_un
.res
.ttls
, 255, MAXVIFS
);
822 for (vifi
= 0; vifi
< mrt
->maxvif
; vifi
++) {
823 if (VIF_EXISTS(mrt
, vifi
) &&
824 ttls
[vifi
] && ttls
[vifi
] < 255) {
825 cache
->mfc_un
.res
.ttls
[vifi
] = ttls
[vifi
];
826 if (cache
->mfc_un
.res
.minvif
> vifi
)
827 cache
->mfc_un
.res
.minvif
= vifi
;
828 if (cache
->mfc_un
.res
.maxvif
<= vifi
)
829 cache
->mfc_un
.res
.maxvif
= vifi
+ 1;
832 cache
->mfc_un
.res
.lastuse
= jiffies
;
835 static int vif_add(struct net
*net
, struct mr_table
*mrt
,
836 struct vifctl
*vifc
, int mrtsock
)
838 int vifi
= vifc
->vifc_vifi
;
839 struct switchdev_attr attr
= {
840 .id
= SWITCHDEV_ATTR_ID_PORT_PARENT_ID
,
842 struct vif_device
*v
= &mrt
->vif_table
[vifi
];
843 struct net_device
*dev
;
844 struct in_device
*in_dev
;
848 if (VIF_EXISTS(mrt
, vifi
))
851 switch (vifc
->vifc_flags
) {
853 if (!ipmr_pimsm_enabled())
855 /* Special Purpose VIF in PIM
856 * All the packets will be sent to the daemon
858 if (mrt
->mroute_reg_vif_num
>= 0)
860 dev
= ipmr_reg_vif(net
, mrt
);
863 err
= dev_set_allmulti(dev
, 1);
865 unregister_netdevice(dev
);
871 dev
= ipmr_new_tunnel(net
, vifc
);
874 err
= dev_set_allmulti(dev
, 1);
876 ipmr_del_tunnel(dev
, vifc
);
881 case VIFF_USE_IFINDEX
:
883 if (vifc
->vifc_flags
== VIFF_USE_IFINDEX
) {
884 dev
= dev_get_by_index(net
, vifc
->vifc_lcl_ifindex
);
885 if (dev
&& !__in_dev_get_rtnl(dev
)) {
887 return -EADDRNOTAVAIL
;
890 dev
= ip_dev_find(net
, vifc
->vifc_lcl_addr
.s_addr
);
893 return -EADDRNOTAVAIL
;
894 err
= dev_set_allmulti(dev
, 1);
904 in_dev
= __in_dev_get_rtnl(dev
);
907 return -EADDRNOTAVAIL
;
909 IPV4_DEVCONF(in_dev
->cnf
, MC_FORWARDING
)++;
910 inet_netconf_notify_devconf(net
, RTM_NEWNETCONF
, NETCONFA_MC_FORWARDING
,
911 dev
->ifindex
, &in_dev
->cnf
);
912 ip_rt_multicast_event(in_dev
);
914 /* Fill in the VIF structures */
915 vif_device_init(v
, dev
, vifc
->vifc_rate_limit
,
916 vifc
->vifc_threshold
,
917 vifc
->vifc_flags
| (!mrtsock
? VIFF_STATIC
: 0),
918 (VIFF_TUNNEL
| VIFF_REGISTER
));
921 if (!switchdev_port_attr_get(dev
, &attr
)) {
922 memcpy(v
->dev_parent_id
.id
, attr
.u
.ppid
.id
, attr
.u
.ppid
.id_len
);
923 v
->dev_parent_id
.id_len
= attr
.u
.ppid
.id_len
;
925 v
->dev_parent_id
.id_len
= 0;
928 v
->local
= vifc
->vifc_lcl_addr
.s_addr
;
929 v
->remote
= vifc
->vifc_rmt_addr
.s_addr
;
931 /* And finish update writing critical data */
932 write_lock_bh(&mrt_lock
);
934 if (v
->flags
& VIFF_REGISTER
)
935 mrt
->mroute_reg_vif_num
= vifi
;
936 if (vifi
+1 > mrt
->maxvif
)
937 mrt
->maxvif
= vifi
+1;
938 write_unlock_bh(&mrt_lock
);
939 call_ipmr_vif_entry_notifiers(net
, FIB_EVENT_VIF_ADD
, v
, vifi
, mrt
->id
);
943 /* called with rcu_read_lock() */
944 static struct mfc_cache
*ipmr_cache_find(struct mr_table
*mrt
,
948 struct mfc_cache_cmp_arg arg
= {
949 .mfc_mcastgrp
= mcastgrp
,
953 return mr_mfc_find(mrt
, &arg
);
956 /* Look for a (*,G) entry */
957 static struct mfc_cache
*ipmr_cache_find_any(struct mr_table
*mrt
,
958 __be32 mcastgrp
, int vifi
)
960 struct mfc_cache_cmp_arg arg
= {
961 .mfc_mcastgrp
= mcastgrp
,
962 .mfc_origin
= htonl(INADDR_ANY
)
965 if (mcastgrp
== htonl(INADDR_ANY
))
966 return mr_mfc_find_any_parent(mrt
, vifi
);
967 return mr_mfc_find_any(mrt
, vifi
, &arg
);
970 /* Look for a (S,G,iif) entry if parent != -1 */
971 static struct mfc_cache
*ipmr_cache_find_parent(struct mr_table
*mrt
,
972 __be32 origin
, __be32 mcastgrp
,
975 struct mfc_cache_cmp_arg arg
= {
976 .mfc_mcastgrp
= mcastgrp
,
977 .mfc_origin
= origin
,
980 return mr_mfc_find_parent(mrt
, &arg
, parent
);
983 /* Allocate a multicast cache entry */
984 static struct mfc_cache
*ipmr_cache_alloc(void)
986 struct mfc_cache
*c
= kmem_cache_zalloc(mrt_cachep
, GFP_KERNEL
);
989 c
->_c
.mfc_un
.res
.last_assert
= jiffies
- MFC_ASSERT_THRESH
- 1;
990 c
->_c
.mfc_un
.res
.minvif
= MAXVIFS
;
991 c
->_c
.free
= ipmr_cache_free_rcu
;
992 refcount_set(&c
->_c
.mfc_un
.res
.refcount
, 1);
997 static struct mfc_cache
*ipmr_cache_alloc_unres(void)
999 struct mfc_cache
*c
= kmem_cache_zalloc(mrt_cachep
, GFP_ATOMIC
);
1002 skb_queue_head_init(&c
->_c
.mfc_un
.unres
.unresolved
);
1003 c
->_c
.mfc_un
.unres
.expires
= jiffies
+ 10 * HZ
;
1008 /* A cache entry has gone into a resolved state from queued */
1009 static void ipmr_cache_resolve(struct net
*net
, struct mr_table
*mrt
,
1010 struct mfc_cache
*uc
, struct mfc_cache
*c
)
1012 struct sk_buff
*skb
;
1015 /* Play the pending entries through our router */
1016 while ((skb
= __skb_dequeue(&uc
->_c
.mfc_un
.unres
.unresolved
))) {
1017 if (ip_hdr(skb
)->version
== 0) {
1018 struct nlmsghdr
*nlh
= skb_pull(skb
,
1019 sizeof(struct iphdr
));
1021 if (mr_fill_mroute(mrt
, skb
, &c
->_c
,
1022 nlmsg_data(nlh
)) > 0) {
1023 nlh
->nlmsg_len
= skb_tail_pointer(skb
) -
1026 nlh
->nlmsg_type
= NLMSG_ERROR
;
1027 nlh
->nlmsg_len
= nlmsg_msg_size(sizeof(struct nlmsgerr
));
1028 skb_trim(skb
, nlh
->nlmsg_len
);
1029 e
= nlmsg_data(nlh
);
1030 e
->error
= -EMSGSIZE
;
1031 memset(&e
->msg
, 0, sizeof(e
->msg
));
1034 rtnl_unicast(skb
, net
, NETLINK_CB(skb
).portid
);
1036 ip_mr_forward(net
, mrt
, skb
->dev
, skb
, c
, 0);
1041 /* Bounce a cache query up to mrouted and netlink.
1043 * Called under mrt_lock.
1045 static int ipmr_cache_report(struct mr_table
*mrt
,
1046 struct sk_buff
*pkt
, vifi_t vifi
, int assert)
1048 const int ihl
= ip_hdrlen(pkt
);
1049 struct sock
*mroute_sk
;
1050 struct igmphdr
*igmp
;
1051 struct igmpmsg
*msg
;
1052 struct sk_buff
*skb
;
1055 if (assert == IGMPMSG_WHOLEPKT
|| assert == IGMPMSG_WRVIFWHOLE
)
1056 skb
= skb_realloc_headroom(pkt
, sizeof(struct iphdr
));
1058 skb
= alloc_skb(128, GFP_ATOMIC
);
1063 if (assert == IGMPMSG_WHOLEPKT
|| assert == IGMPMSG_WRVIFWHOLE
) {
1064 /* Ugly, but we have no choice with this interface.
1065 * Duplicate old header, fix ihl, length etc.
1066 * And all this only to mangle msg->im_msgtype and
1067 * to set msg->im_mbz to "mbz" :-)
1069 skb_push(skb
, sizeof(struct iphdr
));
1070 skb_reset_network_header(skb
);
1071 skb_reset_transport_header(skb
);
1072 msg
= (struct igmpmsg
*)skb_network_header(skb
);
1073 memcpy(msg
, skb_network_header(pkt
), sizeof(struct iphdr
));
1074 msg
->im_msgtype
= assert;
1076 if (assert == IGMPMSG_WRVIFWHOLE
)
1079 msg
->im_vif
= mrt
->mroute_reg_vif_num
;
1080 ip_hdr(skb
)->ihl
= sizeof(struct iphdr
) >> 2;
1081 ip_hdr(skb
)->tot_len
= htons(ntohs(ip_hdr(pkt
)->tot_len
) +
1082 sizeof(struct iphdr
));
1084 /* Copy the IP header */
1085 skb_set_network_header(skb
, skb
->len
);
1087 skb_copy_to_linear_data(skb
, pkt
->data
, ihl
);
1088 /* Flag to the kernel this is a route add */
1089 ip_hdr(skb
)->protocol
= 0;
1090 msg
= (struct igmpmsg
*)skb_network_header(skb
);
1092 skb_dst_set(skb
, dst_clone(skb_dst(pkt
)));
1093 /* Add our header */
1094 igmp
= skb_put(skb
, sizeof(struct igmphdr
));
1095 igmp
->type
= assert;
1096 msg
->im_msgtype
= assert;
1098 ip_hdr(skb
)->tot_len
= htons(skb
->len
); /* Fix the length */
1099 skb
->transport_header
= skb
->network_header
;
1103 mroute_sk
= rcu_dereference(mrt
->mroute_sk
);
1110 igmpmsg_netlink_event(mrt
, skb
);
1112 /* Deliver to mrouted */
1113 ret
= sock_queue_rcv_skb(mroute_sk
, skb
);
1116 net_warn_ratelimited("mroute: pending queue full, dropping entries\n");
1123 /* Queue a packet for resolution. It gets locked cache entry! */
1124 static int ipmr_cache_unresolved(struct mr_table
*mrt
, vifi_t vifi
,
1125 struct sk_buff
*skb
, struct net_device
*dev
)
1127 const struct iphdr
*iph
= ip_hdr(skb
);
1128 struct mfc_cache
*c
;
1132 spin_lock_bh(&mfc_unres_lock
);
1133 list_for_each_entry(c
, &mrt
->mfc_unres_queue
, _c
.list
) {
1134 if (c
->mfc_mcastgrp
== iph
->daddr
&&
1135 c
->mfc_origin
== iph
->saddr
) {
1142 /* Create a new entry if allowable */
1143 if (atomic_read(&mrt
->cache_resolve_queue_len
) >= 10 ||
1144 (c
= ipmr_cache_alloc_unres()) == NULL
) {
1145 spin_unlock_bh(&mfc_unres_lock
);
1151 /* Fill in the new cache entry */
1152 c
->_c
.mfc_parent
= -1;
1153 c
->mfc_origin
= iph
->saddr
;
1154 c
->mfc_mcastgrp
= iph
->daddr
;
1156 /* Reflect first query at mrouted. */
1157 err
= ipmr_cache_report(mrt
, skb
, vifi
, IGMPMSG_NOCACHE
);
1160 /* If the report failed throw the cache entry
1163 spin_unlock_bh(&mfc_unres_lock
);
1170 atomic_inc(&mrt
->cache_resolve_queue_len
);
1171 list_add(&c
->_c
.list
, &mrt
->mfc_unres_queue
);
1172 mroute_netlink_event(mrt
, c
, RTM_NEWROUTE
);
1174 if (atomic_read(&mrt
->cache_resolve_queue_len
) == 1)
1175 mod_timer(&mrt
->ipmr_expire_timer
,
1176 c
->_c
.mfc_un
.unres
.expires
);
1179 /* See if we can append the packet */
1180 if (c
->_c
.mfc_un
.unres
.unresolved
.qlen
> 3) {
1186 skb
->skb_iif
= dev
->ifindex
;
1188 skb_queue_tail(&c
->_c
.mfc_un
.unres
.unresolved
, skb
);
1192 spin_unlock_bh(&mfc_unres_lock
);
1196 /* MFC cache manipulation by user space mroute daemon */
1198 static int ipmr_mfc_delete(struct mr_table
*mrt
, struct mfcctl
*mfc
, int parent
)
1200 struct net
*net
= read_pnet(&mrt
->net
);
1201 struct mfc_cache
*c
;
1203 /* The entries are added/deleted only under RTNL */
1205 c
= ipmr_cache_find_parent(mrt
, mfc
->mfcc_origin
.s_addr
,
1206 mfc
->mfcc_mcastgrp
.s_addr
, parent
);
1210 rhltable_remove(&mrt
->mfc_hash
, &c
->_c
.mnode
, ipmr_rht_params
);
1211 list_del_rcu(&c
->_c
.list
);
1212 call_ipmr_mfc_entry_notifiers(net
, FIB_EVENT_ENTRY_DEL
, c
, mrt
->id
);
1213 mroute_netlink_event(mrt
, c
, RTM_DELROUTE
);
1214 mr_cache_put(&c
->_c
);
1219 static int ipmr_mfc_add(struct net
*net
, struct mr_table
*mrt
,
1220 struct mfcctl
*mfc
, int mrtsock
, int parent
)
1222 struct mfc_cache
*uc
, *c
;
1227 if (mfc
->mfcc_parent
>= MAXVIFS
)
1230 /* The entries are added/deleted only under RTNL */
1232 c
= ipmr_cache_find_parent(mrt
, mfc
->mfcc_origin
.s_addr
,
1233 mfc
->mfcc_mcastgrp
.s_addr
, parent
);
1236 write_lock_bh(&mrt_lock
);
1237 c
->_c
.mfc_parent
= mfc
->mfcc_parent
;
1238 ipmr_update_thresholds(mrt
, &c
->_c
, mfc
->mfcc_ttls
);
1240 c
->_c
.mfc_flags
|= MFC_STATIC
;
1241 write_unlock_bh(&mrt_lock
);
1242 call_ipmr_mfc_entry_notifiers(net
, FIB_EVENT_ENTRY_REPLACE
, c
,
1244 mroute_netlink_event(mrt
, c
, RTM_NEWROUTE
);
1248 if (mfc
->mfcc_mcastgrp
.s_addr
!= htonl(INADDR_ANY
) &&
1249 !ipv4_is_multicast(mfc
->mfcc_mcastgrp
.s_addr
))
1252 c
= ipmr_cache_alloc();
1256 c
->mfc_origin
= mfc
->mfcc_origin
.s_addr
;
1257 c
->mfc_mcastgrp
= mfc
->mfcc_mcastgrp
.s_addr
;
1258 c
->_c
.mfc_parent
= mfc
->mfcc_parent
;
1259 ipmr_update_thresholds(mrt
, &c
->_c
, mfc
->mfcc_ttls
);
1261 c
->_c
.mfc_flags
|= MFC_STATIC
;
1263 ret
= rhltable_insert_key(&mrt
->mfc_hash
, &c
->cmparg
, &c
->_c
.mnode
,
1266 pr_err("ipmr: rhtable insert error %d\n", ret
);
1270 list_add_tail_rcu(&c
->_c
.list
, &mrt
->mfc_cache_list
);
1271 /* Check to see if we resolved a queued list. If so we
1272 * need to send on the frames and tidy up.
1275 spin_lock_bh(&mfc_unres_lock
);
1276 list_for_each_entry(_uc
, &mrt
->mfc_unres_queue
, list
) {
1277 uc
= (struct mfc_cache
*)_uc
;
1278 if (uc
->mfc_origin
== c
->mfc_origin
&&
1279 uc
->mfc_mcastgrp
== c
->mfc_mcastgrp
) {
1280 list_del(&_uc
->list
);
1281 atomic_dec(&mrt
->cache_resolve_queue_len
);
1286 if (list_empty(&mrt
->mfc_unres_queue
))
1287 del_timer(&mrt
->ipmr_expire_timer
);
1288 spin_unlock_bh(&mfc_unres_lock
);
1291 ipmr_cache_resolve(net
, mrt
, uc
, c
);
1292 ipmr_cache_free(uc
);
1294 call_ipmr_mfc_entry_notifiers(net
, FIB_EVENT_ENTRY_ADD
, c
, mrt
->id
);
1295 mroute_netlink_event(mrt
, c
, RTM_NEWROUTE
);
1299 /* Close the multicast socket, and clear the vif tables etc */
1300 static void mroute_clean_tables(struct mr_table
*mrt
, bool all
)
1302 struct net
*net
= read_pnet(&mrt
->net
);
1303 struct mr_mfc
*c
, *tmp
;
1304 struct mfc_cache
*cache
;
1308 /* Shut down all active vif entries */
1309 for (i
= 0; i
< mrt
->maxvif
; i
++) {
1310 if (!all
&& (mrt
->vif_table
[i
].flags
& VIFF_STATIC
))
1312 vif_delete(mrt
, i
, 0, &list
);
1314 unregister_netdevice_many(&list
);
1316 /* Wipe the cache */
1317 list_for_each_entry_safe(c
, tmp
, &mrt
->mfc_cache_list
, list
) {
1318 if (!all
&& (c
->mfc_flags
& MFC_STATIC
))
1320 rhltable_remove(&mrt
->mfc_hash
, &c
->mnode
, ipmr_rht_params
);
1321 list_del_rcu(&c
->list
);
1322 cache
= (struct mfc_cache
*)c
;
1323 call_ipmr_mfc_entry_notifiers(net
, FIB_EVENT_ENTRY_DEL
, cache
,
1325 mroute_netlink_event(mrt
, cache
, RTM_DELROUTE
);
1329 if (atomic_read(&mrt
->cache_resolve_queue_len
) != 0) {
1330 spin_lock_bh(&mfc_unres_lock
);
1331 list_for_each_entry_safe(c
, tmp
, &mrt
->mfc_unres_queue
, list
) {
1333 cache
= (struct mfc_cache
*)c
;
1334 mroute_netlink_event(mrt
, cache
, RTM_DELROUTE
);
1335 ipmr_destroy_unres(mrt
, cache
);
1337 spin_unlock_bh(&mfc_unres_lock
);
1341 /* called from ip_ra_control(), before an RCU grace period,
1342 * we dont need to call synchronize_rcu() here
1344 static void mrtsock_destruct(struct sock
*sk
)
1346 struct net
*net
= sock_net(sk
);
1347 struct mr_table
*mrt
;
1350 ipmr_for_each_table(mrt
, net
) {
1351 if (sk
== rtnl_dereference(mrt
->mroute_sk
)) {
1352 IPV4_DEVCONF_ALL(net
, MC_FORWARDING
)--;
1353 inet_netconf_notify_devconf(net
, RTM_NEWNETCONF
,
1354 NETCONFA_MC_FORWARDING
,
1355 NETCONFA_IFINDEX_ALL
,
1356 net
->ipv4
.devconf_all
);
1357 RCU_INIT_POINTER(mrt
->mroute_sk
, NULL
);
1358 mroute_clean_tables(mrt
, false);
1364 /* Socket options and virtual interface manipulation. The whole
1365 * virtual interface system is a complete heap, but unfortunately
1366 * that's how BSD mrouted happens to think. Maybe one day with a proper
1367 * MOSPF/PIM router set up we can clean this up.
1370 int ip_mroute_setsockopt(struct sock
*sk
, int optname
, char __user
*optval
,
1371 unsigned int optlen
)
1373 struct net
*net
= sock_net(sk
);
1374 int val
, ret
= 0, parent
= 0;
1375 struct mr_table
*mrt
;
1381 /* There's one exception to the lock - MRT_DONE which needs to unlock */
1383 if (sk
->sk_type
!= SOCK_RAW
||
1384 inet_sk(sk
)->inet_num
!= IPPROTO_IGMP
) {
1389 mrt
= ipmr_get_table(net
, raw_sk(sk
)->ipmr_table
? : RT_TABLE_DEFAULT
);
1394 if (optname
!= MRT_INIT
) {
1395 if (sk
!= rcu_access_pointer(mrt
->mroute_sk
) &&
1396 !ns_capable(net
->user_ns
, CAP_NET_ADMIN
)) {
1404 if (optlen
!= sizeof(int)) {
1408 if (rtnl_dereference(mrt
->mroute_sk
)) {
1413 ret
= ip_ra_control(sk
, 1, mrtsock_destruct
);
1415 rcu_assign_pointer(mrt
->mroute_sk
, sk
);
1416 IPV4_DEVCONF_ALL(net
, MC_FORWARDING
)++;
1417 inet_netconf_notify_devconf(net
, RTM_NEWNETCONF
,
1418 NETCONFA_MC_FORWARDING
,
1419 NETCONFA_IFINDEX_ALL
,
1420 net
->ipv4
.devconf_all
);
1424 if (sk
!= rcu_access_pointer(mrt
->mroute_sk
)) {
1427 /* We need to unlock here because mrtsock_destruct takes
1428 * care of rtnl itself and we can't change that due to
1429 * the IP_ROUTER_ALERT setsockopt which runs without it.
1432 ret
= ip_ra_control(sk
, 0, NULL
);
1438 if (optlen
!= sizeof(vif
)) {
1442 if (copy_from_user(&vif
, optval
, sizeof(vif
))) {
1446 if (vif
.vifc_vifi
>= MAXVIFS
) {
1450 if (optname
== MRT_ADD_VIF
) {
1451 ret
= vif_add(net
, mrt
, &vif
,
1452 sk
== rtnl_dereference(mrt
->mroute_sk
));
1454 ret
= vif_delete(mrt
, vif
.vifc_vifi
, 0, NULL
);
1457 /* Manipulate the forwarding caches. These live
1458 * in a sort of kernel/user symbiosis.
1464 case MRT_ADD_MFC_PROXY
:
1465 case MRT_DEL_MFC_PROXY
:
1466 if (optlen
!= sizeof(mfc
)) {
1470 if (copy_from_user(&mfc
, optval
, sizeof(mfc
))) {
1475 parent
= mfc
.mfcc_parent
;
1476 if (optname
== MRT_DEL_MFC
|| optname
== MRT_DEL_MFC_PROXY
)
1477 ret
= ipmr_mfc_delete(mrt
, &mfc
, parent
);
1479 ret
= ipmr_mfc_add(net
, mrt
, &mfc
,
1480 sk
== rtnl_dereference(mrt
->mroute_sk
),
1483 /* Control PIM assert. */
1485 if (optlen
!= sizeof(val
)) {
1489 if (get_user(val
, (int __user
*)optval
)) {
1493 mrt
->mroute_do_assert
= val
;
1496 if (!ipmr_pimsm_enabled()) {
1500 if (optlen
!= sizeof(val
)) {
1504 if (get_user(val
, (int __user
*)optval
)) {
1509 do_wrvifwhole
= (val
== IGMPMSG_WRVIFWHOLE
);
1511 if (val
!= mrt
->mroute_do_pim
) {
1512 mrt
->mroute_do_pim
= val
;
1513 mrt
->mroute_do_assert
= val
;
1514 mrt
->mroute_do_wrvifwhole
= do_wrvifwhole
;
1518 if (!IS_BUILTIN(CONFIG_IP_MROUTE_MULTIPLE_TABLES
)) {
1522 if (optlen
!= sizeof(uval
)) {
1526 if (get_user(uval
, (u32 __user
*)optval
)) {
1531 if (sk
== rtnl_dereference(mrt
->mroute_sk
)) {
1534 mrt
= ipmr_new_table(net
, uval
);
1538 raw_sk(sk
)->ipmr_table
= uval
;
1541 /* Spurious command, or MRT_VERSION which you cannot set. */
1551 /* Getsock opt support for the multicast routing system. */
1552 int ip_mroute_getsockopt(struct sock
*sk
, int optname
, char __user
*optval
, int __user
*optlen
)
1556 struct net
*net
= sock_net(sk
);
1557 struct mr_table
*mrt
;
1559 if (sk
->sk_type
!= SOCK_RAW
||
1560 inet_sk(sk
)->inet_num
!= IPPROTO_IGMP
)
1563 mrt
= ipmr_get_table(net
, raw_sk(sk
)->ipmr_table
? : RT_TABLE_DEFAULT
);
1572 if (!ipmr_pimsm_enabled())
1573 return -ENOPROTOOPT
;
1574 val
= mrt
->mroute_do_pim
;
1577 val
= mrt
->mroute_do_assert
;
1580 return -ENOPROTOOPT
;
1583 if (get_user(olr
, optlen
))
1585 olr
= min_t(unsigned int, olr
, sizeof(int));
1588 if (put_user(olr
, optlen
))
1590 if (copy_to_user(optval
, &val
, olr
))
1595 /* The IP multicast ioctl support routines. */
1596 int ipmr_ioctl(struct sock
*sk
, int cmd
, void __user
*arg
)
1598 struct sioc_sg_req sr
;
1599 struct sioc_vif_req vr
;
1600 struct vif_device
*vif
;
1601 struct mfc_cache
*c
;
1602 struct net
*net
= sock_net(sk
);
1603 struct mr_table
*mrt
;
1605 mrt
= ipmr_get_table(net
, raw_sk(sk
)->ipmr_table
? : RT_TABLE_DEFAULT
);
1611 if (copy_from_user(&vr
, arg
, sizeof(vr
)))
1613 if (vr
.vifi
>= mrt
->maxvif
)
1615 read_lock(&mrt_lock
);
1616 vif
= &mrt
->vif_table
[vr
.vifi
];
1617 if (VIF_EXISTS(mrt
, vr
.vifi
)) {
1618 vr
.icount
= vif
->pkt_in
;
1619 vr
.ocount
= vif
->pkt_out
;
1620 vr
.ibytes
= vif
->bytes_in
;
1621 vr
.obytes
= vif
->bytes_out
;
1622 read_unlock(&mrt_lock
);
1624 if (copy_to_user(arg
, &vr
, sizeof(vr
)))
1628 read_unlock(&mrt_lock
);
1629 return -EADDRNOTAVAIL
;
1631 if (copy_from_user(&sr
, arg
, sizeof(sr
)))
1635 c
= ipmr_cache_find(mrt
, sr
.src
.s_addr
, sr
.grp
.s_addr
);
1637 sr
.pktcnt
= c
->_c
.mfc_un
.res
.pkt
;
1638 sr
.bytecnt
= c
->_c
.mfc_un
.res
.bytes
;
1639 sr
.wrong_if
= c
->_c
.mfc_un
.res
.wrong_if
;
1642 if (copy_to_user(arg
, &sr
, sizeof(sr
)))
1647 return -EADDRNOTAVAIL
;
1649 return -ENOIOCTLCMD
;
1653 #ifdef CONFIG_COMPAT
1654 struct compat_sioc_sg_req
{
1657 compat_ulong_t pktcnt
;
1658 compat_ulong_t bytecnt
;
1659 compat_ulong_t wrong_if
;
1662 struct compat_sioc_vif_req
{
1663 vifi_t vifi
; /* Which iface */
1664 compat_ulong_t icount
;
1665 compat_ulong_t ocount
;
1666 compat_ulong_t ibytes
;
1667 compat_ulong_t obytes
;
1670 int ipmr_compat_ioctl(struct sock
*sk
, unsigned int cmd
, void __user
*arg
)
1672 struct compat_sioc_sg_req sr
;
1673 struct compat_sioc_vif_req vr
;
1674 struct vif_device
*vif
;
1675 struct mfc_cache
*c
;
1676 struct net
*net
= sock_net(sk
);
1677 struct mr_table
*mrt
;
1679 mrt
= ipmr_get_table(net
, raw_sk(sk
)->ipmr_table
? : RT_TABLE_DEFAULT
);
1685 if (copy_from_user(&vr
, arg
, sizeof(vr
)))
1687 if (vr
.vifi
>= mrt
->maxvif
)
1689 read_lock(&mrt_lock
);
1690 vif
= &mrt
->vif_table
[vr
.vifi
];
1691 if (VIF_EXISTS(mrt
, vr
.vifi
)) {
1692 vr
.icount
= vif
->pkt_in
;
1693 vr
.ocount
= vif
->pkt_out
;
1694 vr
.ibytes
= vif
->bytes_in
;
1695 vr
.obytes
= vif
->bytes_out
;
1696 read_unlock(&mrt_lock
);
1698 if (copy_to_user(arg
, &vr
, sizeof(vr
)))
1702 read_unlock(&mrt_lock
);
1703 return -EADDRNOTAVAIL
;
1705 if (copy_from_user(&sr
, arg
, sizeof(sr
)))
1709 c
= ipmr_cache_find(mrt
, sr
.src
.s_addr
, sr
.grp
.s_addr
);
1711 sr
.pktcnt
= c
->_c
.mfc_un
.res
.pkt
;
1712 sr
.bytecnt
= c
->_c
.mfc_un
.res
.bytes
;
1713 sr
.wrong_if
= c
->_c
.mfc_un
.res
.wrong_if
;
1716 if (copy_to_user(arg
, &sr
, sizeof(sr
)))
1721 return -EADDRNOTAVAIL
;
1723 return -ENOIOCTLCMD
;
1728 static int ipmr_device_event(struct notifier_block
*this, unsigned long event
, void *ptr
)
1730 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
1731 struct net
*net
= dev_net(dev
);
1732 struct mr_table
*mrt
;
1733 struct vif_device
*v
;
1736 if (event
!= NETDEV_UNREGISTER
)
1739 ipmr_for_each_table(mrt
, net
) {
1740 v
= &mrt
->vif_table
[0];
1741 for (ct
= 0; ct
< mrt
->maxvif
; ct
++, v
++) {
1743 vif_delete(mrt
, ct
, 1, NULL
);
1749 static struct notifier_block ip_mr_notifier
= {
1750 .notifier_call
= ipmr_device_event
,
1753 /* Encapsulate a packet by attaching a valid IPIP header to it.
1754 * This avoids tunnel drivers and other mess and gives us the speed so
1755 * important for multicast video.
1757 static void ip_encap(struct net
*net
, struct sk_buff
*skb
,
1758 __be32 saddr
, __be32 daddr
)
1761 const struct iphdr
*old_iph
= ip_hdr(skb
);
1763 skb_push(skb
, sizeof(struct iphdr
));
1764 skb
->transport_header
= skb
->network_header
;
1765 skb_reset_network_header(skb
);
1769 iph
->tos
= old_iph
->tos
;
1770 iph
->ttl
= old_iph
->ttl
;
1774 iph
->protocol
= IPPROTO_IPIP
;
1776 iph
->tot_len
= htons(skb
->len
);
1777 ip_select_ident(net
, skb
, NULL
);
1780 memset(&(IPCB(skb
)->opt
), 0, sizeof(IPCB(skb
)->opt
));
1784 static inline int ipmr_forward_finish(struct net
*net
, struct sock
*sk
,
1785 struct sk_buff
*skb
)
1787 struct ip_options
*opt
= &(IPCB(skb
)->opt
);
1789 IP_INC_STATS(net
, IPSTATS_MIB_OUTFORWDATAGRAMS
);
1790 IP_ADD_STATS(net
, IPSTATS_MIB_OUTOCTETS
, skb
->len
);
1792 if (unlikely(opt
->optlen
))
1793 ip_forward_options(skb
);
1795 return dst_output(net
, sk
, skb
);
1798 #ifdef CONFIG_NET_SWITCHDEV
1799 static bool ipmr_forward_offloaded(struct sk_buff
*skb
, struct mr_table
*mrt
,
1800 int in_vifi
, int out_vifi
)
1802 struct vif_device
*out_vif
= &mrt
->vif_table
[out_vifi
];
1803 struct vif_device
*in_vif
= &mrt
->vif_table
[in_vifi
];
1805 if (!skb
->offload_mr_fwd_mark
)
1807 if (!out_vif
->dev_parent_id
.id_len
|| !in_vif
->dev_parent_id
.id_len
)
1809 return netdev_phys_item_id_same(&out_vif
->dev_parent_id
,
1810 &in_vif
->dev_parent_id
);
1813 static bool ipmr_forward_offloaded(struct sk_buff
*skb
, struct mr_table
*mrt
,
1814 int in_vifi
, int out_vifi
)
1820 /* Processing handlers for ipmr_forward */
1822 static void ipmr_queue_xmit(struct net
*net
, struct mr_table
*mrt
,
1823 int in_vifi
, struct sk_buff
*skb
,
1824 struct mfc_cache
*c
, int vifi
)
1826 const struct iphdr
*iph
= ip_hdr(skb
);
1827 struct vif_device
*vif
= &mrt
->vif_table
[vifi
];
1828 struct net_device
*dev
;
1836 if (vif
->flags
& VIFF_REGISTER
) {
1838 vif
->bytes_out
+= skb
->len
;
1839 vif
->dev
->stats
.tx_bytes
+= skb
->len
;
1840 vif
->dev
->stats
.tx_packets
++;
1841 ipmr_cache_report(mrt
, skb
, vifi
, IGMPMSG_WHOLEPKT
);
1845 if (ipmr_forward_offloaded(skb
, mrt
, in_vifi
, vifi
))
1848 if (vif
->flags
& VIFF_TUNNEL
) {
1849 rt
= ip_route_output_ports(net
, &fl4
, NULL
,
1850 vif
->remote
, vif
->local
,
1853 RT_TOS(iph
->tos
), vif
->link
);
1856 encap
= sizeof(struct iphdr
);
1858 rt
= ip_route_output_ports(net
, &fl4
, NULL
, iph
->daddr
, 0,
1861 RT_TOS(iph
->tos
), vif
->link
);
1868 if (skb
->len
+encap
> dst_mtu(&rt
->dst
) && (ntohs(iph
->frag_off
) & IP_DF
)) {
1869 /* Do not fragment multicasts. Alas, IPv4 does not
1870 * allow to send ICMP, so that packets will disappear
1873 IP_INC_STATS(net
, IPSTATS_MIB_FRAGFAILS
);
1878 encap
+= LL_RESERVED_SPACE(dev
) + rt
->dst
.header_len
;
1880 if (skb_cow(skb
, encap
)) {
1886 vif
->bytes_out
+= skb
->len
;
1889 skb_dst_set(skb
, &rt
->dst
);
1890 ip_decrease_ttl(ip_hdr(skb
));
1892 /* FIXME: forward and output firewalls used to be called here.
1893 * What do we do with netfilter? -- RR
1895 if (vif
->flags
& VIFF_TUNNEL
) {
1896 ip_encap(net
, skb
, vif
->local
, vif
->remote
);
1897 /* FIXME: extra output firewall step used to be here. --RR */
1898 vif
->dev
->stats
.tx_packets
++;
1899 vif
->dev
->stats
.tx_bytes
+= skb
->len
;
1902 IPCB(skb
)->flags
|= IPSKB_FORWARDED
;
1904 /* RFC1584 teaches, that DVMRP/PIM router must deliver packets locally
1905 * not only before forwarding, but after forwarding on all output
1906 * interfaces. It is clear, if mrouter runs a multicasting
1907 * program, it should receive packets not depending to what interface
1908 * program is joined.
1909 * If we will not make it, the program will have to join on all
1910 * interfaces. On the other hand, multihoming host (or router, but
1911 * not mrouter) cannot join to more than one interface - it will
1912 * result in receiving multiple packets.
1914 NF_HOOK(NFPROTO_IPV4
, NF_INET_FORWARD
,
1915 net
, NULL
, skb
, skb
->dev
, dev
,
1916 ipmr_forward_finish
);
1923 static int ipmr_find_vif(struct mr_table
*mrt
, struct net_device
*dev
)
1927 for (ct
= mrt
->maxvif
-1; ct
>= 0; ct
--) {
1928 if (mrt
->vif_table
[ct
].dev
== dev
)
1934 /* "local" means that we should preserve one skb (for local delivery) */
1935 static void ip_mr_forward(struct net
*net
, struct mr_table
*mrt
,
1936 struct net_device
*dev
, struct sk_buff
*skb
,
1937 struct mfc_cache
*c
, int local
)
1939 int true_vifi
= ipmr_find_vif(mrt
, dev
);
1943 vif
= c
->_c
.mfc_parent
;
1944 c
->_c
.mfc_un
.res
.pkt
++;
1945 c
->_c
.mfc_un
.res
.bytes
+= skb
->len
;
1946 c
->_c
.mfc_un
.res
.lastuse
= jiffies
;
1948 if (c
->mfc_origin
== htonl(INADDR_ANY
) && true_vifi
>= 0) {
1949 struct mfc_cache
*cache_proxy
;
1951 /* For an (*,G) entry, we only check that the incomming
1952 * interface is part of the static tree.
1954 cache_proxy
= mr_mfc_find_any_parent(mrt
, vif
);
1956 cache_proxy
->_c
.mfc_un
.res
.ttls
[true_vifi
] < 255)
1960 /* Wrong interface: drop packet and (maybe) send PIM assert. */
1961 if (mrt
->vif_table
[vif
].dev
!= dev
) {
1962 if (rt_is_output_route(skb_rtable(skb
))) {
1963 /* It is our own packet, looped back.
1964 * Very complicated situation...
1966 * The best workaround until routing daemons will be
1967 * fixed is not to redistribute packet, if it was
1968 * send through wrong interface. It means, that
1969 * multicast applications WILL NOT work for
1970 * (S,G), which have default multicast route pointing
1971 * to wrong oif. In any case, it is not a good
1972 * idea to use multicasting applications on router.
1977 c
->_c
.mfc_un
.res
.wrong_if
++;
1979 if (true_vifi
>= 0 && mrt
->mroute_do_assert
&&
1980 /* pimsm uses asserts, when switching from RPT to SPT,
1981 * so that we cannot check that packet arrived on an oif.
1982 * It is bad, but otherwise we would need to move pretty
1983 * large chunk of pimd to kernel. Ough... --ANK
1985 (mrt
->mroute_do_pim
||
1986 c
->_c
.mfc_un
.res
.ttls
[true_vifi
] < 255) &&
1988 c
->_c
.mfc_un
.res
.last_assert
+
1989 MFC_ASSERT_THRESH
)) {
1990 c
->_c
.mfc_un
.res
.last_assert
= jiffies
;
1991 ipmr_cache_report(mrt
, skb
, true_vifi
, IGMPMSG_WRONGVIF
);
1992 if (mrt
->mroute_do_wrvifwhole
)
1993 ipmr_cache_report(mrt
, skb
, true_vifi
,
1994 IGMPMSG_WRVIFWHOLE
);
2000 mrt
->vif_table
[vif
].pkt_in
++;
2001 mrt
->vif_table
[vif
].bytes_in
+= skb
->len
;
2003 /* Forward the frame */
2004 if (c
->mfc_origin
== htonl(INADDR_ANY
) &&
2005 c
->mfc_mcastgrp
== htonl(INADDR_ANY
)) {
2006 if (true_vifi
>= 0 &&
2007 true_vifi
!= c
->_c
.mfc_parent
&&
2009 c
->_c
.mfc_un
.res
.ttls
[c
->_c
.mfc_parent
]) {
2010 /* It's an (*,*) entry and the packet is not coming from
2011 * the upstream: forward the packet to the upstream
2014 psend
= c
->_c
.mfc_parent
;
2019 for (ct
= c
->_c
.mfc_un
.res
.maxvif
- 1;
2020 ct
>= c
->_c
.mfc_un
.res
.minvif
; ct
--) {
2021 /* For (*,G) entry, don't forward to the incoming interface */
2022 if ((c
->mfc_origin
!= htonl(INADDR_ANY
) ||
2024 ip_hdr(skb
)->ttl
> c
->_c
.mfc_un
.res
.ttls
[ct
]) {
2026 struct sk_buff
*skb2
= skb_clone(skb
, GFP_ATOMIC
);
2029 ipmr_queue_xmit(net
, mrt
, true_vifi
,
2038 struct sk_buff
*skb2
= skb_clone(skb
, GFP_ATOMIC
);
2041 ipmr_queue_xmit(net
, mrt
, true_vifi
, skb2
,
2044 ipmr_queue_xmit(net
, mrt
, true_vifi
, skb
, c
, psend
);
2054 static struct mr_table
*ipmr_rt_fib_lookup(struct net
*net
, struct sk_buff
*skb
)
2056 struct rtable
*rt
= skb_rtable(skb
);
2057 struct iphdr
*iph
= ip_hdr(skb
);
2058 struct flowi4 fl4
= {
2059 .daddr
= iph
->daddr
,
2060 .saddr
= iph
->saddr
,
2061 .flowi4_tos
= RT_TOS(iph
->tos
),
2062 .flowi4_oif
= (rt_is_output_route(rt
) ?
2063 skb
->dev
->ifindex
: 0),
2064 .flowi4_iif
= (rt_is_output_route(rt
) ?
2067 .flowi4_mark
= skb
->mark
,
2069 struct mr_table
*mrt
;
2072 err
= ipmr_fib_lookup(net
, &fl4
, &mrt
);
2074 return ERR_PTR(err
);
2078 /* Multicast packets for forwarding arrive here
2079 * Called with rcu_read_lock();
2081 int ip_mr_input(struct sk_buff
*skb
)
2083 struct mfc_cache
*cache
;
2084 struct net
*net
= dev_net(skb
->dev
);
2085 int local
= skb_rtable(skb
)->rt_flags
& RTCF_LOCAL
;
2086 struct mr_table
*mrt
;
2087 struct net_device
*dev
;
2089 /* skb->dev passed in is the loX master dev for vrfs.
2090 * As there are no vifs associated with loopback devices,
2091 * get the proper interface that does have a vif associated with it.
2094 if (netif_is_l3_master(skb
->dev
)) {
2095 dev
= dev_get_by_index_rcu(net
, IPCB(skb
)->iif
);
2102 /* Packet is looped back after forward, it should not be
2103 * forwarded second time, but still can be delivered locally.
2105 if (IPCB(skb
)->flags
& IPSKB_FORWARDED
)
2108 mrt
= ipmr_rt_fib_lookup(net
, skb
);
2111 return PTR_ERR(mrt
);
2114 if (IPCB(skb
)->opt
.router_alert
) {
2115 if (ip_call_ra_chain(skb
))
2117 } else if (ip_hdr(skb
)->protocol
== IPPROTO_IGMP
) {
2118 /* IGMPv1 (and broken IGMPv2 implementations sort of
2119 * Cisco IOS <= 11.2(8)) do not put router alert
2120 * option to IGMP packets destined to routable
2121 * groups. It is very bad, because it means
2122 * that we can forward NO IGMP messages.
2124 struct sock
*mroute_sk
;
2126 mroute_sk
= rcu_dereference(mrt
->mroute_sk
);
2129 raw_rcv(mroute_sk
, skb
);
2135 /* already under rcu_read_lock() */
2136 cache
= ipmr_cache_find(mrt
, ip_hdr(skb
)->saddr
, ip_hdr(skb
)->daddr
);
2138 int vif
= ipmr_find_vif(mrt
, dev
);
2141 cache
= ipmr_cache_find_any(mrt
, ip_hdr(skb
)->daddr
,
2145 /* No usable cache entry */
2150 struct sk_buff
*skb2
= skb_clone(skb
, GFP_ATOMIC
);
2151 ip_local_deliver(skb
);
2157 read_lock(&mrt_lock
);
2158 vif
= ipmr_find_vif(mrt
, dev
);
2160 int err2
= ipmr_cache_unresolved(mrt
, vif
, skb
, dev
);
2161 read_unlock(&mrt_lock
);
2165 read_unlock(&mrt_lock
);
2170 read_lock(&mrt_lock
);
2171 ip_mr_forward(net
, mrt
, dev
, skb
, cache
, local
);
2172 read_unlock(&mrt_lock
);
2175 return ip_local_deliver(skb
);
2181 return ip_local_deliver(skb
);
2186 #ifdef CONFIG_IP_PIMSM_V1
2187 /* Handle IGMP messages of PIMv1 */
2188 int pim_rcv_v1(struct sk_buff
*skb
)
2190 struct igmphdr
*pim
;
2191 struct net
*net
= dev_net(skb
->dev
);
2192 struct mr_table
*mrt
;
2194 if (!pskb_may_pull(skb
, sizeof(*pim
) + sizeof(struct iphdr
)))
2197 pim
= igmp_hdr(skb
);
2199 mrt
= ipmr_rt_fib_lookup(net
, skb
);
2202 if (!mrt
->mroute_do_pim
||
2203 pim
->group
!= PIM_V1_VERSION
|| pim
->code
!= PIM_V1_REGISTER
)
2206 if (__pim_rcv(mrt
, skb
, sizeof(*pim
))) {
2214 #ifdef CONFIG_IP_PIMSM_V2
2215 static int pim_rcv(struct sk_buff
*skb
)
2217 struct pimreghdr
*pim
;
2218 struct net
*net
= dev_net(skb
->dev
);
2219 struct mr_table
*mrt
;
2221 if (!pskb_may_pull(skb
, sizeof(*pim
) + sizeof(struct iphdr
)))
2224 pim
= (struct pimreghdr
*)skb_transport_header(skb
);
2225 if (pim
->type
!= ((PIM_VERSION
<< 4) | (PIM_TYPE_REGISTER
)) ||
2226 (pim
->flags
& PIM_NULL_REGISTER
) ||
2227 (ip_compute_csum((void *)pim
, sizeof(*pim
)) != 0 &&
2228 csum_fold(skb_checksum(skb
, 0, skb
->len
, 0))))
2231 mrt
= ipmr_rt_fib_lookup(net
, skb
);
2234 if (__pim_rcv(mrt
, skb
, sizeof(*pim
))) {
2242 int ipmr_get_route(struct net
*net
, struct sk_buff
*skb
,
2243 __be32 saddr
, __be32 daddr
,
2244 struct rtmsg
*rtm
, u32 portid
)
2246 struct mfc_cache
*cache
;
2247 struct mr_table
*mrt
;
2250 mrt
= ipmr_get_table(net
, RT_TABLE_DEFAULT
);
2255 cache
= ipmr_cache_find(mrt
, saddr
, daddr
);
2256 if (!cache
&& skb
->dev
) {
2257 int vif
= ipmr_find_vif(mrt
, skb
->dev
);
2260 cache
= ipmr_cache_find_any(mrt
, daddr
, vif
);
2263 struct sk_buff
*skb2
;
2265 struct net_device
*dev
;
2269 read_lock(&mrt_lock
);
2271 vif
= ipmr_find_vif(mrt
, dev
);
2273 read_unlock(&mrt_lock
);
2277 skb2
= skb_clone(skb
, GFP_ATOMIC
);
2279 read_unlock(&mrt_lock
);
2284 NETLINK_CB(skb2
).portid
= portid
;
2285 skb_push(skb2
, sizeof(struct iphdr
));
2286 skb_reset_network_header(skb2
);
2288 iph
->ihl
= sizeof(struct iphdr
) >> 2;
2292 err
= ipmr_cache_unresolved(mrt
, vif
, skb2
, dev
);
2293 read_unlock(&mrt_lock
);
2298 read_lock(&mrt_lock
);
2299 err
= mr_fill_mroute(mrt
, skb
, &cache
->_c
, rtm
);
2300 read_unlock(&mrt_lock
);
2305 static int ipmr_fill_mroute(struct mr_table
*mrt
, struct sk_buff
*skb
,
2306 u32 portid
, u32 seq
, struct mfc_cache
*c
, int cmd
,
2309 struct nlmsghdr
*nlh
;
2313 nlh
= nlmsg_put(skb
, portid
, seq
, cmd
, sizeof(*rtm
), flags
);
2317 rtm
= nlmsg_data(nlh
);
2318 rtm
->rtm_family
= RTNL_FAMILY_IPMR
;
2319 rtm
->rtm_dst_len
= 32;
2320 rtm
->rtm_src_len
= 32;
2322 rtm
->rtm_table
= mrt
->id
;
2323 if (nla_put_u32(skb
, RTA_TABLE
, mrt
->id
))
2324 goto nla_put_failure
;
2325 rtm
->rtm_type
= RTN_MULTICAST
;
2326 rtm
->rtm_scope
= RT_SCOPE_UNIVERSE
;
2327 if (c
->_c
.mfc_flags
& MFC_STATIC
)
2328 rtm
->rtm_protocol
= RTPROT_STATIC
;
2330 rtm
->rtm_protocol
= RTPROT_MROUTED
;
2333 if (nla_put_in_addr(skb
, RTA_SRC
, c
->mfc_origin
) ||
2334 nla_put_in_addr(skb
, RTA_DST
, c
->mfc_mcastgrp
))
2335 goto nla_put_failure
;
2336 err
= mr_fill_mroute(mrt
, skb
, &c
->_c
, rtm
);
2337 /* do not break the dump if cache is unresolved */
2338 if (err
< 0 && err
!= -ENOENT
)
2339 goto nla_put_failure
;
2341 nlmsg_end(skb
, nlh
);
2345 nlmsg_cancel(skb
, nlh
);
2349 static int _ipmr_fill_mroute(struct mr_table
*mrt
, struct sk_buff
*skb
,
2350 u32 portid
, u32 seq
, struct mr_mfc
*c
, int cmd
,
2353 return ipmr_fill_mroute(mrt
, skb
, portid
, seq
, (struct mfc_cache
*)c
,
2357 static size_t mroute_msgsize(bool unresolved
, int maxvif
)
2360 NLMSG_ALIGN(sizeof(struct rtmsg
))
2361 + nla_total_size(4) /* RTA_TABLE */
2362 + nla_total_size(4) /* RTA_SRC */
2363 + nla_total_size(4) /* RTA_DST */
2368 + nla_total_size(4) /* RTA_IIF */
2369 + nla_total_size(0) /* RTA_MULTIPATH */
2370 + maxvif
* NLA_ALIGN(sizeof(struct rtnexthop
))
2372 + nla_total_size_64bit(sizeof(struct rta_mfc_stats
))
2378 static void mroute_netlink_event(struct mr_table
*mrt
, struct mfc_cache
*mfc
,
2381 struct net
*net
= read_pnet(&mrt
->net
);
2382 struct sk_buff
*skb
;
2385 skb
= nlmsg_new(mroute_msgsize(mfc
->_c
.mfc_parent
>= MAXVIFS
,
2391 err
= ipmr_fill_mroute(mrt
, skb
, 0, 0, mfc
, cmd
, 0);
2395 rtnl_notify(skb
, net
, 0, RTNLGRP_IPV4_MROUTE
, NULL
, GFP_ATOMIC
);
2401 rtnl_set_sk_err(net
, RTNLGRP_IPV4_MROUTE
, err
);
2404 static size_t igmpmsg_netlink_msgsize(size_t payloadlen
)
2407 NLMSG_ALIGN(sizeof(struct rtgenmsg
))
2408 + nla_total_size(1) /* IPMRA_CREPORT_MSGTYPE */
2409 + nla_total_size(4) /* IPMRA_CREPORT_VIF_ID */
2410 + nla_total_size(4) /* IPMRA_CREPORT_SRC_ADDR */
2411 + nla_total_size(4) /* IPMRA_CREPORT_DST_ADDR */
2412 /* IPMRA_CREPORT_PKT */
2413 + nla_total_size(payloadlen
)
2419 static void igmpmsg_netlink_event(struct mr_table
*mrt
, struct sk_buff
*pkt
)
2421 struct net
*net
= read_pnet(&mrt
->net
);
2422 struct nlmsghdr
*nlh
;
2423 struct rtgenmsg
*rtgenm
;
2424 struct igmpmsg
*msg
;
2425 struct sk_buff
*skb
;
2429 payloadlen
= pkt
->len
- sizeof(struct igmpmsg
);
2430 msg
= (struct igmpmsg
*)skb_network_header(pkt
);
2432 skb
= nlmsg_new(igmpmsg_netlink_msgsize(payloadlen
), GFP_ATOMIC
);
2436 nlh
= nlmsg_put(skb
, 0, 0, RTM_NEWCACHEREPORT
,
2437 sizeof(struct rtgenmsg
), 0);
2440 rtgenm
= nlmsg_data(nlh
);
2441 rtgenm
->rtgen_family
= RTNL_FAMILY_IPMR
;
2442 if (nla_put_u8(skb
, IPMRA_CREPORT_MSGTYPE
, msg
->im_msgtype
) ||
2443 nla_put_u32(skb
, IPMRA_CREPORT_VIF_ID
, msg
->im_vif
) ||
2444 nla_put_in_addr(skb
, IPMRA_CREPORT_SRC_ADDR
,
2445 msg
->im_src
.s_addr
) ||
2446 nla_put_in_addr(skb
, IPMRA_CREPORT_DST_ADDR
,
2447 msg
->im_dst
.s_addr
))
2448 goto nla_put_failure
;
2450 nla
= nla_reserve(skb
, IPMRA_CREPORT_PKT
, payloadlen
);
2451 if (!nla
|| skb_copy_bits(pkt
, sizeof(struct igmpmsg
),
2452 nla_data(nla
), payloadlen
))
2453 goto nla_put_failure
;
2455 nlmsg_end(skb
, nlh
);
2457 rtnl_notify(skb
, net
, 0, RTNLGRP_IPV4_MROUTE_R
, NULL
, GFP_ATOMIC
);
2461 nlmsg_cancel(skb
, nlh
);
2464 rtnl_set_sk_err(net
, RTNLGRP_IPV4_MROUTE_R
, -ENOBUFS
);
2467 static int ipmr_rtm_getroute(struct sk_buff
*in_skb
, struct nlmsghdr
*nlh
,
2468 struct netlink_ext_ack
*extack
)
2470 struct net
*net
= sock_net(in_skb
->sk
);
2471 struct nlattr
*tb
[RTA_MAX
+ 1];
2472 struct sk_buff
*skb
= NULL
;
2473 struct mfc_cache
*cache
;
2474 struct mr_table
*mrt
;
2480 err
= nlmsg_parse(nlh
, sizeof(*rtm
), tb
, RTA_MAX
,
2481 rtm_ipv4_policy
, extack
);
2485 rtm
= nlmsg_data(nlh
);
2487 src
= tb
[RTA_SRC
] ? nla_get_in_addr(tb
[RTA_SRC
]) : 0;
2488 grp
= tb
[RTA_DST
] ? nla_get_in_addr(tb
[RTA_DST
]) : 0;
2489 tableid
= tb
[RTA_TABLE
] ? nla_get_u32(tb
[RTA_TABLE
]) : 0;
2491 mrt
= ipmr_get_table(net
, tableid
? tableid
: RT_TABLE_DEFAULT
);
2497 /* entries are added/deleted only under RTNL */
2499 cache
= ipmr_cache_find(mrt
, src
, grp
);
2506 skb
= nlmsg_new(mroute_msgsize(false, mrt
->maxvif
), GFP_KERNEL
);
2512 err
= ipmr_fill_mroute(mrt
, skb
, NETLINK_CB(in_skb
).portid
,
2513 nlh
->nlmsg_seq
, cache
,
2518 err
= rtnl_unicast(skb
, net
, NETLINK_CB(in_skb
).portid
);
2528 static int ipmr_rtm_dumproute(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2530 struct fib_dump_filter filter
= {};
2533 if (cb
->strict_check
) {
2534 err
= ip_valid_fib_dump_req(sock_net(skb
->sk
), cb
->nlh
,
2540 if (filter
.table_id
) {
2541 struct mr_table
*mrt
;
2543 mrt
= ipmr_get_table(sock_net(skb
->sk
), filter
.table_id
);
2545 if (filter
.dump_all_families
)
2548 NL_SET_ERR_MSG(cb
->extack
, "ipv4: MR table does not exist");
2551 err
= mr_table_dump(mrt
, skb
, cb
, _ipmr_fill_mroute
,
2552 &mfc_unres_lock
, &filter
);
2553 return skb
->len
? : err
;
2556 return mr_rtm_dumproute(skb
, cb
, ipmr_mr_table_iter
,
2557 _ipmr_fill_mroute
, &mfc_unres_lock
, &filter
);
2560 static const struct nla_policy rtm_ipmr_policy
[RTA_MAX
+ 1] = {
2561 [RTA_SRC
] = { .type
= NLA_U32
},
2562 [RTA_DST
] = { .type
= NLA_U32
},
2563 [RTA_IIF
] = { .type
= NLA_U32
},
2564 [RTA_TABLE
] = { .type
= NLA_U32
},
2565 [RTA_MULTIPATH
] = { .len
= sizeof(struct rtnexthop
) },
2568 static bool ipmr_rtm_validate_proto(unsigned char rtm_protocol
)
2570 switch (rtm_protocol
) {
2572 case RTPROT_MROUTED
:
2578 static int ipmr_nla_get_ttls(const struct nlattr
*nla
, struct mfcctl
*mfcc
)
2580 struct rtnexthop
*rtnh
= nla_data(nla
);
2581 int remaining
= nla_len(nla
), vifi
= 0;
2583 while (rtnh_ok(rtnh
, remaining
)) {
2584 mfcc
->mfcc_ttls
[vifi
] = rtnh
->rtnh_hops
;
2585 if (++vifi
== MAXVIFS
)
2587 rtnh
= rtnh_next(rtnh
, &remaining
);
2590 return remaining
> 0 ? -EINVAL
: vifi
;
2593 /* returns < 0 on error, 0 for ADD_MFC and 1 for ADD_MFC_PROXY */
2594 static int rtm_to_ipmr_mfcc(struct net
*net
, struct nlmsghdr
*nlh
,
2595 struct mfcctl
*mfcc
, int *mrtsock
,
2596 struct mr_table
**mrtret
,
2597 struct netlink_ext_ack
*extack
)
2599 struct net_device
*dev
= NULL
;
2600 u32 tblid
= RT_TABLE_DEFAULT
;
2601 struct mr_table
*mrt
;
2602 struct nlattr
*attr
;
2606 ret
= nlmsg_validate(nlh
, sizeof(*rtm
), RTA_MAX
, rtm_ipmr_policy
,
2610 rtm
= nlmsg_data(nlh
);
2613 if (rtm
->rtm_family
!= RTNL_FAMILY_IPMR
|| rtm
->rtm_dst_len
!= 32 ||
2614 rtm
->rtm_type
!= RTN_MULTICAST
||
2615 rtm
->rtm_scope
!= RT_SCOPE_UNIVERSE
||
2616 !ipmr_rtm_validate_proto(rtm
->rtm_protocol
))
2619 memset(mfcc
, 0, sizeof(*mfcc
));
2620 mfcc
->mfcc_parent
= -1;
2622 nlmsg_for_each_attr(attr
, nlh
, sizeof(struct rtmsg
), rem
) {
2623 switch (nla_type(attr
)) {
2625 mfcc
->mfcc_origin
.s_addr
= nla_get_be32(attr
);
2628 mfcc
->mfcc_mcastgrp
.s_addr
= nla_get_be32(attr
);
2631 dev
= __dev_get_by_index(net
, nla_get_u32(attr
));
2638 if (ipmr_nla_get_ttls(attr
, mfcc
) < 0) {
2647 tblid
= nla_get_u32(attr
);
2651 mrt
= ipmr_get_table(net
, tblid
);
2657 *mrtsock
= rtm
->rtm_protocol
== RTPROT_MROUTED
? 1 : 0;
2659 mfcc
->mfcc_parent
= ipmr_find_vif(mrt
, dev
);
2665 /* takes care of both newroute and delroute */
2666 static int ipmr_rtm_route(struct sk_buff
*skb
, struct nlmsghdr
*nlh
,
2667 struct netlink_ext_ack
*extack
)
2669 struct net
*net
= sock_net(skb
->sk
);
2670 int ret
, mrtsock
, parent
;
2671 struct mr_table
*tbl
;
2676 ret
= rtm_to_ipmr_mfcc(net
, nlh
, &mfcc
, &mrtsock
, &tbl
, extack
);
2680 parent
= ret
? mfcc
.mfcc_parent
: -1;
2681 if (nlh
->nlmsg_type
== RTM_NEWROUTE
)
2682 return ipmr_mfc_add(net
, tbl
, &mfcc
, mrtsock
, parent
);
2684 return ipmr_mfc_delete(tbl
, &mfcc
, parent
);
2687 static bool ipmr_fill_table(struct mr_table
*mrt
, struct sk_buff
*skb
)
2689 u32 queue_len
= atomic_read(&mrt
->cache_resolve_queue_len
);
2691 if (nla_put_u32(skb
, IPMRA_TABLE_ID
, mrt
->id
) ||
2692 nla_put_u32(skb
, IPMRA_TABLE_CACHE_RES_QUEUE_LEN
, queue_len
) ||
2693 nla_put_s32(skb
, IPMRA_TABLE_MROUTE_REG_VIF_NUM
,
2694 mrt
->mroute_reg_vif_num
) ||
2695 nla_put_u8(skb
, IPMRA_TABLE_MROUTE_DO_ASSERT
,
2696 mrt
->mroute_do_assert
) ||
2697 nla_put_u8(skb
, IPMRA_TABLE_MROUTE_DO_PIM
, mrt
->mroute_do_pim
) ||
2698 nla_put_u8(skb
, IPMRA_TABLE_MROUTE_DO_WRVIFWHOLE
,
2699 mrt
->mroute_do_wrvifwhole
))
2705 static bool ipmr_fill_vif(struct mr_table
*mrt
, u32 vifid
, struct sk_buff
*skb
)
2707 struct nlattr
*vif_nest
;
2708 struct vif_device
*vif
;
2710 /* if the VIF doesn't exist just continue */
2711 if (!VIF_EXISTS(mrt
, vifid
))
2714 vif
= &mrt
->vif_table
[vifid
];
2715 vif_nest
= nla_nest_start(skb
, IPMRA_VIF
);
2718 if (nla_put_u32(skb
, IPMRA_VIFA_IFINDEX
, vif
->dev
->ifindex
) ||
2719 nla_put_u32(skb
, IPMRA_VIFA_VIF_ID
, vifid
) ||
2720 nla_put_u16(skb
, IPMRA_VIFA_FLAGS
, vif
->flags
) ||
2721 nla_put_u64_64bit(skb
, IPMRA_VIFA_BYTES_IN
, vif
->bytes_in
,
2723 nla_put_u64_64bit(skb
, IPMRA_VIFA_BYTES_OUT
, vif
->bytes_out
,
2725 nla_put_u64_64bit(skb
, IPMRA_VIFA_PACKETS_IN
, vif
->pkt_in
,
2727 nla_put_u64_64bit(skb
, IPMRA_VIFA_PACKETS_OUT
, vif
->pkt_out
,
2729 nla_put_be32(skb
, IPMRA_VIFA_LOCAL_ADDR
, vif
->local
) ||
2730 nla_put_be32(skb
, IPMRA_VIFA_REMOTE_ADDR
, vif
->remote
)) {
2731 nla_nest_cancel(skb
, vif_nest
);
2734 nla_nest_end(skb
, vif_nest
);
2739 static int ipmr_valid_dumplink(const struct nlmsghdr
*nlh
,
2740 struct netlink_ext_ack
*extack
)
2742 struct ifinfomsg
*ifm
;
2744 if (nlh
->nlmsg_len
< nlmsg_msg_size(sizeof(*ifm
))) {
2745 NL_SET_ERR_MSG(extack
, "ipv4: Invalid header for ipmr link dump");
2749 if (nlmsg_attrlen(nlh
, sizeof(*ifm
))) {
2750 NL_SET_ERR_MSG(extack
, "Invalid data after header in ipmr link dump");
2754 ifm
= nlmsg_data(nlh
);
2755 if (ifm
->__ifi_pad
|| ifm
->ifi_type
|| ifm
->ifi_flags
||
2756 ifm
->ifi_change
|| ifm
->ifi_index
) {
2757 NL_SET_ERR_MSG(extack
, "Invalid values in header for ipmr link dump request");
2764 static int ipmr_rtm_dumplink(struct sk_buff
*skb
, struct netlink_callback
*cb
)
2766 struct net
*net
= sock_net(skb
->sk
);
2767 struct nlmsghdr
*nlh
= NULL
;
2768 unsigned int t
= 0, s_t
;
2769 unsigned int e
= 0, s_e
;
2770 struct mr_table
*mrt
;
2772 if (cb
->strict_check
) {
2773 int err
= ipmr_valid_dumplink(cb
->nlh
, cb
->extack
);
2782 ipmr_for_each_table(mrt
, net
) {
2783 struct nlattr
*vifs
, *af
;
2784 struct ifinfomsg
*hdr
;
2789 nlh
= nlmsg_put(skb
, NETLINK_CB(cb
->skb
).portid
,
2790 cb
->nlh
->nlmsg_seq
, RTM_NEWLINK
,
2791 sizeof(*hdr
), NLM_F_MULTI
);
2795 hdr
= nlmsg_data(nlh
);
2796 memset(hdr
, 0, sizeof(*hdr
));
2797 hdr
->ifi_family
= RTNL_FAMILY_IPMR
;
2799 af
= nla_nest_start(skb
, IFLA_AF_SPEC
);
2801 nlmsg_cancel(skb
, nlh
);
2805 if (!ipmr_fill_table(mrt
, skb
)) {
2806 nlmsg_cancel(skb
, nlh
);
2810 vifs
= nla_nest_start(skb
, IPMRA_TABLE_VIFS
);
2812 nla_nest_end(skb
, af
);
2813 nlmsg_end(skb
, nlh
);
2816 for (i
= 0; i
< mrt
->maxvif
; i
++) {
2819 if (!ipmr_fill_vif(mrt
, i
, skb
)) {
2820 nla_nest_end(skb
, vifs
);
2821 nla_nest_end(skb
, af
);
2822 nlmsg_end(skb
, nlh
);
2830 nla_nest_end(skb
, vifs
);
2831 nla_nest_end(skb
, af
);
2832 nlmsg_end(skb
, nlh
);
2844 #ifdef CONFIG_PROC_FS
2845 /* The /proc interfaces to multicast routing :
2846 * /proc/net/ip_mr_cache & /proc/net/ip_mr_vif
2849 static void *ipmr_vif_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2850 __acquires(mrt_lock
)
2852 struct mr_vif_iter
*iter
= seq
->private;
2853 struct net
*net
= seq_file_net(seq
);
2854 struct mr_table
*mrt
;
2856 mrt
= ipmr_get_table(net
, RT_TABLE_DEFAULT
);
2858 return ERR_PTR(-ENOENT
);
2862 read_lock(&mrt_lock
);
2863 return mr_vif_seq_start(seq
, pos
);
2866 static void ipmr_vif_seq_stop(struct seq_file
*seq
, void *v
)
2867 __releases(mrt_lock
)
2869 read_unlock(&mrt_lock
);
2872 static int ipmr_vif_seq_show(struct seq_file
*seq
, void *v
)
2874 struct mr_vif_iter
*iter
= seq
->private;
2875 struct mr_table
*mrt
= iter
->mrt
;
2877 if (v
== SEQ_START_TOKEN
) {
2879 "Interface BytesIn PktsIn BytesOut PktsOut Flags Local Remote\n");
2881 const struct vif_device
*vif
= v
;
2882 const char *name
= vif
->dev
?
2883 vif
->dev
->name
: "none";
2886 "%2td %-10s %8ld %7ld %8ld %7ld %05X %08X %08X\n",
2887 vif
- mrt
->vif_table
,
2888 name
, vif
->bytes_in
, vif
->pkt_in
,
2889 vif
->bytes_out
, vif
->pkt_out
,
2890 vif
->flags
, vif
->local
, vif
->remote
);
2895 static const struct seq_operations ipmr_vif_seq_ops
= {
2896 .start
= ipmr_vif_seq_start
,
2897 .next
= mr_vif_seq_next
,
2898 .stop
= ipmr_vif_seq_stop
,
2899 .show
= ipmr_vif_seq_show
,
2902 static void *ipmr_mfc_seq_start(struct seq_file
*seq
, loff_t
*pos
)
2904 struct net
*net
= seq_file_net(seq
);
2905 struct mr_table
*mrt
;
2907 mrt
= ipmr_get_table(net
, RT_TABLE_DEFAULT
);
2909 return ERR_PTR(-ENOENT
);
2911 return mr_mfc_seq_start(seq
, pos
, mrt
, &mfc_unres_lock
);
2914 static int ipmr_mfc_seq_show(struct seq_file
*seq
, void *v
)
2918 if (v
== SEQ_START_TOKEN
) {
2920 "Group Origin Iif Pkts Bytes Wrong Oifs\n");
2922 const struct mfc_cache
*mfc
= v
;
2923 const struct mr_mfc_iter
*it
= seq
->private;
2924 const struct mr_table
*mrt
= it
->mrt
;
2926 seq_printf(seq
, "%08X %08X %-3hd",
2927 (__force u32
) mfc
->mfc_mcastgrp
,
2928 (__force u32
) mfc
->mfc_origin
,
2929 mfc
->_c
.mfc_parent
);
2931 if (it
->cache
!= &mrt
->mfc_unres_queue
) {
2932 seq_printf(seq
, " %8lu %8lu %8lu",
2933 mfc
->_c
.mfc_un
.res
.pkt
,
2934 mfc
->_c
.mfc_un
.res
.bytes
,
2935 mfc
->_c
.mfc_un
.res
.wrong_if
);
2936 for (n
= mfc
->_c
.mfc_un
.res
.minvif
;
2937 n
< mfc
->_c
.mfc_un
.res
.maxvif
; n
++) {
2938 if (VIF_EXISTS(mrt
, n
) &&
2939 mfc
->_c
.mfc_un
.res
.ttls
[n
] < 255)
2942 n
, mfc
->_c
.mfc_un
.res
.ttls
[n
]);
2945 /* unresolved mfc_caches don't contain
2946 * pkt, bytes and wrong_if values
2948 seq_printf(seq
, " %8lu %8lu %8lu", 0ul, 0ul, 0ul);
2950 seq_putc(seq
, '\n');
2955 static const struct seq_operations ipmr_mfc_seq_ops
= {
2956 .start
= ipmr_mfc_seq_start
,
2957 .next
= mr_mfc_seq_next
,
2958 .stop
= mr_mfc_seq_stop
,
2959 .show
= ipmr_mfc_seq_show
,
2963 #ifdef CONFIG_IP_PIMSM_V2
2964 static const struct net_protocol pim_protocol
= {
2970 static unsigned int ipmr_seq_read(struct net
*net
)
2974 return net
->ipv4
.ipmr_seq
+ ipmr_rules_seq_read(net
);
2977 static int ipmr_dump(struct net
*net
, struct notifier_block
*nb
)
2979 return mr_dump(net
, nb
, RTNL_FAMILY_IPMR
, ipmr_rules_dump
,
2980 ipmr_mr_table_iter
, &mrt_lock
);
2983 static const struct fib_notifier_ops ipmr_notifier_ops_template
= {
2984 .family
= RTNL_FAMILY_IPMR
,
2985 .fib_seq_read
= ipmr_seq_read
,
2986 .fib_dump
= ipmr_dump
,
2987 .owner
= THIS_MODULE
,
2990 static int __net_init
ipmr_notifier_init(struct net
*net
)
2992 struct fib_notifier_ops
*ops
;
2994 net
->ipv4
.ipmr_seq
= 0;
2996 ops
= fib_notifier_ops_register(&ipmr_notifier_ops_template
, net
);
2998 return PTR_ERR(ops
);
2999 net
->ipv4
.ipmr_notifier_ops
= ops
;
3004 static void __net_exit
ipmr_notifier_exit(struct net
*net
)
3006 fib_notifier_ops_unregister(net
->ipv4
.ipmr_notifier_ops
);
3007 net
->ipv4
.ipmr_notifier_ops
= NULL
;
3010 /* Setup for IP multicast routing */
3011 static int __net_init
ipmr_net_init(struct net
*net
)
3015 err
= ipmr_notifier_init(net
);
3017 goto ipmr_notifier_fail
;
3019 err
= ipmr_rules_init(net
);
3021 goto ipmr_rules_fail
;
3023 #ifdef CONFIG_PROC_FS
3025 if (!proc_create_net("ip_mr_vif", 0, net
->proc_net
, &ipmr_vif_seq_ops
,
3026 sizeof(struct mr_vif_iter
)))
3028 if (!proc_create_net("ip_mr_cache", 0, net
->proc_net
, &ipmr_mfc_seq_ops
,
3029 sizeof(struct mr_mfc_iter
)))
3030 goto proc_cache_fail
;
3034 #ifdef CONFIG_PROC_FS
3036 remove_proc_entry("ip_mr_vif", net
->proc_net
);
3038 ipmr_rules_exit(net
);
3041 ipmr_notifier_exit(net
);
3046 static void __net_exit
ipmr_net_exit(struct net
*net
)
3048 #ifdef CONFIG_PROC_FS
3049 remove_proc_entry("ip_mr_cache", net
->proc_net
);
3050 remove_proc_entry("ip_mr_vif", net
->proc_net
);
3052 ipmr_notifier_exit(net
);
3053 ipmr_rules_exit(net
);
3056 static struct pernet_operations ipmr_net_ops
= {
3057 .init
= ipmr_net_init
,
3058 .exit
= ipmr_net_exit
,
3061 int __init
ip_mr_init(void)
3065 mrt_cachep
= kmem_cache_create("ip_mrt_cache",
3066 sizeof(struct mfc_cache
),
3067 0, SLAB_HWCACHE_ALIGN
| SLAB_PANIC
,
3070 err
= register_pernet_subsys(&ipmr_net_ops
);
3072 goto reg_pernet_fail
;
3074 err
= register_netdevice_notifier(&ip_mr_notifier
);
3076 goto reg_notif_fail
;
3077 #ifdef CONFIG_IP_PIMSM_V2
3078 if (inet_add_protocol(&pim_protocol
, IPPROTO_PIM
) < 0) {
3079 pr_err("%s: can't add PIM protocol\n", __func__
);
3081 goto add_proto_fail
;
3084 rtnl_register(RTNL_FAMILY_IPMR
, RTM_GETROUTE
,
3085 ipmr_rtm_getroute
, ipmr_rtm_dumproute
, 0);
3086 rtnl_register(RTNL_FAMILY_IPMR
, RTM_NEWROUTE
,
3087 ipmr_rtm_route
, NULL
, 0);
3088 rtnl_register(RTNL_FAMILY_IPMR
, RTM_DELROUTE
,
3089 ipmr_rtm_route
, NULL
, 0);
3091 rtnl_register(RTNL_FAMILY_IPMR
, RTM_GETLINK
,
3092 NULL
, ipmr_rtm_dumplink
, 0);
3095 #ifdef CONFIG_IP_PIMSM_V2
3097 unregister_netdevice_notifier(&ip_mr_notifier
);
3100 unregister_pernet_subsys(&ipmr_net_ops
);
3102 kmem_cache_destroy(mrt_cachep
);