br_mdb.c (adc47037a7d5c8f89ca428bd840c83ab7b62730c) br_mdb.c (1e9ca45662d6bb65fb60d3fbb7737b081d9cffc9)
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/err.h>
3#include <linux/igmp.h>
4#include <linux/kernel.h>
5#include <linux/netdevice.h>
6#include <linux/rculist.h>
7#include <linux/skbuff.h>
8#include <linux/if_ether.h>

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

776 rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC);
777 return;
778errout:
779 rtnl_set_sk_err(net, RTNLGRP_MDB, err);
780}
781
782static int nlmsg_populate_rtr_fill(struct sk_buff *skb,
783 struct net_device *dev,
1// SPDX-License-Identifier: GPL-2.0
2#include <linux/err.h>
3#include <linux/igmp.h>
4#include <linux/kernel.h>
5#include <linux/netdevice.h>
6#include <linux/rculist.h>
7#include <linux/skbuff.h>
8#include <linux/if_ether.h>

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

776 rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC);
777 return;
778errout:
779 rtnl_set_sk_err(net, RTNLGRP_MDB, err);
780}
781
782static int nlmsg_populate_rtr_fill(struct sk_buff *skb,
783 struct net_device *dev,
784 int ifindex, u32 pid,
784 int ifindex, u16 vid, u32 pid,
785 u32 seq, int type, unsigned int flags)
786{
785 u32 seq, int type, unsigned int flags)
786{
787 struct nlattr *nest, *port_nest;
787 struct br_port_msg *bpm;
788 struct nlmsghdr *nlh;
788 struct br_port_msg *bpm;
789 struct nlmsghdr *nlh;
789 struct nlattr *nest;
790
791 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), 0);
792 if (!nlh)
793 return -EMSGSIZE;
794
795 bpm = nlmsg_data(nlh);
796 memset(bpm, 0, sizeof(*bpm));
797 bpm->family = AF_BRIDGE;
798 bpm->ifindex = dev->ifindex;
799 nest = nla_nest_start_noflag(skb, MDBA_ROUTER);
800 if (!nest)
801 goto cancel;
802
790
791 nlh = nlmsg_put(skb, pid, seq, type, sizeof(*bpm), 0);
792 if (!nlh)
793 return -EMSGSIZE;
794
795 bpm = nlmsg_data(nlh);
796 memset(bpm, 0, sizeof(*bpm));
797 bpm->family = AF_BRIDGE;
798 bpm->ifindex = dev->ifindex;
799 nest = nla_nest_start_noflag(skb, MDBA_ROUTER);
800 if (!nest)
801 goto cancel;
802
803 if (nla_put_u32(skb, MDBA_ROUTER_PORT, ifindex))
803 port_nest = nla_nest_start_noflag(skb, MDBA_ROUTER_PORT);
804 if (!port_nest)
804 goto end;
805 goto end;
806 if (nla_put_nohdr(skb, sizeof(u32), &ifindex)) {
807 nla_nest_cancel(skb, port_nest);
808 goto end;
809 }
810 if (vid && nla_put_u16(skb, MDBA_ROUTER_PATTR_VID, vid)) {
811 nla_nest_cancel(skb, port_nest);
812 goto end;
813 }
814 nla_nest_end(skb, port_nest);
805
806 nla_nest_end(skb, nest);
807 nlmsg_end(skb, nlh);
808 return 0;
809
810end:
811 nla_nest_end(skb, nest);
812cancel:
813 nlmsg_cancel(skb, nlh);
814 return -EMSGSIZE;
815}
816
817static inline size_t rtnl_rtr_nlmsg_size(void)
818{
819 return NLMSG_ALIGN(sizeof(struct br_port_msg))
815
816 nla_nest_end(skb, nest);
817 nlmsg_end(skb, nlh);
818 return 0;
819
820end:
821 nla_nest_end(skb, nest);
822cancel:
823 nlmsg_cancel(skb, nlh);
824 return -EMSGSIZE;
825}
826
827static inline size_t rtnl_rtr_nlmsg_size(void)
828{
829 return NLMSG_ALIGN(sizeof(struct br_port_msg))
820 + nla_total_size(sizeof(__u32));
830 + nla_total_size(sizeof(__u32))
831 + nla_total_size(sizeof(u16));
821}
822
832}
833
823void br_rtr_notify(struct net_device *dev, struct net_bridge_port *port,
834void br_rtr_notify(struct net_device *dev, struct net_bridge_mcast_port *pmctx,
824 int type)
825{
826 struct net *net = dev_net(dev);
827 struct sk_buff *skb;
828 int err = -ENOBUFS;
829 int ifindex;
835 int type)
836{
837 struct net *net = dev_net(dev);
838 struct sk_buff *skb;
839 int err = -ENOBUFS;
840 int ifindex;
841 u16 vid;
830
842
831 ifindex = port ? port->dev->ifindex : 0;
843 ifindex = pmctx ? pmctx->port->dev->ifindex : 0;
844 vid = pmctx && br_multicast_port_ctx_is_vlan(pmctx) ? pmctx->vlan->vid :
845 0;
832 skb = nlmsg_new(rtnl_rtr_nlmsg_size(), GFP_ATOMIC);
833 if (!skb)
834 goto errout;
835
846 skb = nlmsg_new(rtnl_rtr_nlmsg_size(), GFP_ATOMIC);
847 if (!skb)
848 goto errout;
849
836 err = nlmsg_populate_rtr_fill(skb, dev, ifindex, 0, 0, type, NTF_SELF);
850 err = nlmsg_populate_rtr_fill(skb, dev, ifindex, vid, 0, 0, type,
851 NTF_SELF);
837 if (err < 0) {
838 kfree_skb(skb);
839 goto errout;
840 }
841
842 rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC);
843 return;
844

--- 463 unchanged lines hidden ---
852 if (err < 0) {
853 kfree_skb(skb);
854 goto errout;
855 }
856
857 rtnl_notify(skb, net, 0, RTNLGRP_MDB, NULL, GFP_ATOMIC);
858 return;
859

--- 463 unchanged lines hidden ---