Commit 3d3ea5af authored by Vlad Yasevich's avatar Vlad Yasevich Committed by David S. Miller

rtnl: Add support for netdev event to link messages

When netdev events happen, a rtnetlink_event() handler will send
messages for every event in it's white list.  These messages contain
current information about a particular device, but they do not include
the iformation about which event just happened.  So, it is impossible
to tell what just happend for these events.

This patch adds a new extension to RTM_NEWLINK message called IFLA_EVENT
that would have an encoding of event that triggered this
message.  This would allow the the message consumer to easily determine
if it needs to perform certain actions.
Signed-off-by: default avatarVladislav Yasevich <vyasevic@redhat.com>
Acked-by: default avatarDavid Ahern <dsahern@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 34aa83c2
...@@ -18,7 +18,8 @@ extern int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, ...@@ -18,7 +18,8 @@ extern int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst,
void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change, gfp_t flags); void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change, gfp_t flags);
struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev, struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
unsigned change, gfp_t flags); unsigned change, u32 event,
gfp_t flags);
void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev,
gfp_t flags); gfp_t flags);
......
...@@ -157,6 +157,7 @@ enum { ...@@ -157,6 +157,7 @@ enum {
IFLA_GSO_MAX_SIZE, IFLA_GSO_MAX_SIZE,
IFLA_PAD, IFLA_PAD,
IFLA_XDP, IFLA_XDP,
IFLA_EVENT,
__IFLA_MAX __IFLA_MAX
}; };
...@@ -911,4 +912,14 @@ enum { ...@@ -911,4 +912,14 @@ enum {
#define IFLA_XDP_MAX (__IFLA_XDP_MAX - 1) #define IFLA_XDP_MAX (__IFLA_XDP_MAX - 1)
enum {
IFLA_EVENT_NONE,
IFLA_EVENT_REBOOT, /* internal reset / reboot */
IFLA_EVENT_FEATURES, /* change in offload features */
IFLA_EVENT_BONDING_FAILOVER, /* change in active slave */
IFLA_EVENT_NOTIFY_PEERS, /* re-sent grat. arp/ndisc */
IFLA_EVENT_IGMP_RESEND, /* re-sent IGMP JOIN */
IFLA_EVENT_BONDING_OPTIONS, /* change in bonding options */
};
#endif /* _UAPI_LINUX_IF_LINK_H */ #endif /* _UAPI_LINUX_IF_LINK_H */
...@@ -7084,7 +7084,7 @@ static void rollback_registered_many(struct list_head *head) ...@@ -7084,7 +7084,7 @@ static void rollback_registered_many(struct list_head *head)
if (!dev->rtnl_link_ops || if (!dev->rtnl_link_ops ||
dev->rtnl_link_state == RTNL_LINK_INITIALIZED) dev->rtnl_link_state == RTNL_LINK_INITIALIZED)
skb = rtmsg_ifinfo_build_skb(RTM_DELLINK, dev, ~0U, skb = rtmsg_ifinfo_build_skb(RTM_DELLINK, dev, ~0U, 0,
GFP_KERNEL); GFP_KERNEL);
/* /*
......
...@@ -941,6 +941,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, ...@@ -941,6 +941,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
+ nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */ + nla_total_size(MAX_PHYS_ITEM_ID_LEN) /* IFLA_PHYS_SWITCH_ID */
+ nla_total_size(IFNAMSIZ) /* IFLA_PHYS_PORT_NAME */ + nla_total_size(IFNAMSIZ) /* IFLA_PHYS_PORT_NAME */
+ rtnl_xdp_size() /* IFLA_XDP */ + rtnl_xdp_size() /* IFLA_XDP */
+ nla_total_size(4) /* IFLA_EVENT */
+ nla_total_size(1); /* IFLA_PROTO_DOWN */ + nla_total_size(1); /* IFLA_PROTO_DOWN */
} }
...@@ -1282,9 +1283,40 @@ static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev) ...@@ -1282,9 +1283,40 @@ static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
return err; return err;
} }
static u32 rtnl_get_event(unsigned long event)
{
u32 rtnl_event_type = IFLA_EVENT_NONE;
switch (event) {
case NETDEV_REBOOT:
rtnl_event_type = IFLA_EVENT_REBOOT;
break;
case NETDEV_FEAT_CHANGE:
rtnl_event_type = IFLA_EVENT_FEATURES;
break;
case NETDEV_BONDING_FAILOVER:
rtnl_event_type = IFLA_EVENT_BONDING_FAILOVER;
break;
case NETDEV_NOTIFY_PEERS:
rtnl_event_type = IFLA_EVENT_NOTIFY_PEERS;
break;
case NETDEV_RESEND_IGMP:
rtnl_event_type = IFLA_EVENT_IGMP_RESEND;
break;
case NETDEV_CHANGEINFODATA:
rtnl_event_type = IFLA_EVENT_BONDING_OPTIONS;
break;
default:
break;
}
return rtnl_event_type;
}
static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
int type, u32 pid, u32 seq, u32 change, int type, u32 pid, u32 seq, u32 change,
unsigned int flags, u32 ext_filter_mask) unsigned int flags, u32 ext_filter_mask,
u32 event)
{ {
struct ifinfomsg *ifm; struct ifinfomsg *ifm;
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
...@@ -1333,6 +1365,11 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev, ...@@ -1333,6 +1365,11 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
nla_put_u8(skb, IFLA_PROTO_DOWN, dev->proto_down)) nla_put_u8(skb, IFLA_PROTO_DOWN, dev->proto_down))
goto nla_put_failure; goto nla_put_failure;
if (event != IFLA_EVENT_NONE) {
if (nla_put_u32(skb, IFLA_EVENT, event))
goto nla_put_failure;
}
if (rtnl_fill_link_ifmap(skb, dev)) if (rtnl_fill_link_ifmap(skb, dev))
goto nla_put_failure; goto nla_put_failure;
...@@ -1467,6 +1504,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = { ...@@ -1467,6 +1504,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
[IFLA_LINK_NETNSID] = { .type = NLA_S32 }, [IFLA_LINK_NETNSID] = { .type = NLA_S32 },
[IFLA_PROTO_DOWN] = { .type = NLA_U8 }, [IFLA_PROTO_DOWN] = { .type = NLA_U8 },
[IFLA_XDP] = { .type = NLA_NESTED }, [IFLA_XDP] = { .type = NLA_NESTED },
[IFLA_EVENT] = { .type = NLA_U32 },
}; };
static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
...@@ -1626,7 +1664,7 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -1626,7 +1664,7 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
NETLINK_CB(cb->skb).portid, NETLINK_CB(cb->skb).portid,
cb->nlh->nlmsg_seq, 0, cb->nlh->nlmsg_seq, 0,
flags, flags,
ext_filter_mask); ext_filter_mask, 0);
if (err < 0) { if (err < 0) {
if (likely(skb->len)) if (likely(skb->len))
...@@ -2736,7 +2774,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -2736,7 +2774,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
return -ENOBUFS; return -ENOBUFS;
err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).portid, err = rtnl_fill_ifinfo(nskb, dev, RTM_NEWLINK, NETLINK_CB(skb).portid,
nlh->nlmsg_seq, 0, 0, ext_filter_mask); nlh->nlmsg_seq, 0, 0, ext_filter_mask, 0);
if (err < 0) { if (err < 0) {
/* -EMSGSIZE implies BUG in if_nlmsg_size */ /* -EMSGSIZE implies BUG in if_nlmsg_size */
WARN_ON(err == -EMSGSIZE); WARN_ON(err == -EMSGSIZE);
...@@ -2808,7 +2846,8 @@ static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -2808,7 +2846,8 @@ static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
} }
struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev, struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
unsigned int change, gfp_t flags) unsigned int change,
u32 event, gfp_t flags)
{ {
struct net *net = dev_net(dev); struct net *net = dev_net(dev);
struct sk_buff *skb; struct sk_buff *skb;
...@@ -2819,7 +2858,7 @@ struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev, ...@@ -2819,7 +2858,7 @@ struct sk_buff *rtmsg_ifinfo_build_skb(int type, struct net_device *dev,
if (skb == NULL) if (skb == NULL)
goto errout; goto errout;
err = rtnl_fill_ifinfo(skb, dev, type, 0, 0, change, 0, 0); err = rtnl_fill_ifinfo(skb, dev, type, 0, 0, change, 0, 0, event);
if (err < 0) { if (err < 0) {
/* -EMSGSIZE implies BUG in if_nlmsg_size() */ /* -EMSGSIZE implies BUG in if_nlmsg_size() */
WARN_ON(err == -EMSGSIZE); WARN_ON(err == -EMSGSIZE);
...@@ -2840,7 +2879,8 @@ void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, gfp_t flags) ...@@ -2840,7 +2879,8 @@ void rtmsg_ifinfo_send(struct sk_buff *skb, struct net_device *dev, gfp_t flags)
rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, flags); rtnl_notify(skb, net, 0, RTNLGRP_LINK, NULL, flags);
} }
void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change, static void rtmsg_ifinfo_event(int type, struct net_device *dev,
unsigned int change, u32 event,
gfp_t flags) gfp_t flags)
{ {
struct sk_buff *skb; struct sk_buff *skb;
...@@ -2848,10 +2888,16 @@ void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change, ...@@ -2848,10 +2888,16 @@ void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change,
if (dev->reg_state != NETREG_REGISTERED) if (dev->reg_state != NETREG_REGISTERED)
return; return;
skb = rtmsg_ifinfo_build_skb(type, dev, change, flags); skb = rtmsg_ifinfo_build_skb(type, dev, change, event, flags);
if (skb) if (skb)
rtmsg_ifinfo_send(skb, dev, flags); rtmsg_ifinfo_send(skb, dev, flags);
} }
void rtmsg_ifinfo(int type, struct net_device *dev, unsigned int change,
gfp_t flags)
{
rtmsg_ifinfo_event(type, dev, change, IFLA_EVENT_NONE, flags);
}
EXPORT_SYMBOL(rtmsg_ifinfo); EXPORT_SYMBOL(rtmsg_ifinfo);
static int nlmsg_populate_fdb_fill(struct sk_buff *skb, static int nlmsg_populate_fdb_fill(struct sk_buff *skb,
...@@ -4168,7 +4214,8 @@ static int rtnetlink_event(struct notifier_block *this, unsigned long event, voi ...@@ -4168,7 +4214,8 @@ static int rtnetlink_event(struct notifier_block *this, unsigned long event, voi
case NETDEV_NOTIFY_PEERS: case NETDEV_NOTIFY_PEERS:
case NETDEV_RESEND_IGMP: case NETDEV_RESEND_IGMP:
case NETDEV_CHANGEINFODATA: case NETDEV_CHANGEINFODATA:
rtmsg_ifinfo(RTM_NEWLINK, dev, 0, GFP_KERNEL); rtmsg_ifinfo_event(RTM_NEWLINK, dev, 0, rtnl_get_event(event),
GFP_KERNEL);
break; break;
default: default:
break; break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment