* [PATCH net-next 1/3] rtnetlink: add NEWCACHEREPORT message type
2017-06-13 17:08 [PATCH net-next 0/3] ipmr/ip6mr: add Netlink notifications on cache reports Julien Gomes
@ 2017-06-13 17:08 ` Julien Gomes
2017-06-13 17:08 ` [PATCH net-next 2/3] ipmr: add netlink notifications on igmpmsg cache reports Julien Gomes
2017-06-13 17:08 ` [PATCH net-next 3/3] ip6mr: add netlink notifications on mrt6msg " Julien Gomes
2 siblings, 0 replies; 6+ messages in thread
From: Julien Gomes @ 2017-06-13 17:08 UTC (permalink / raw)
To: davem; +Cc: netdev, linux-kernel, nikolay, Julien Gomes
New NEWCACHEREPORT message type to be used for cache reports sent
via Netlink, effectively allowing splitting cache report reception from
mroute programming.
Suggested-by: Ryan Halbrook <halbrook@arista.com>
Signed-off-by: Julien Gomes <julien@arista.com>
---
include/uapi/linux/rtnetlink.h | 3 +++
security/selinux/nlmsgtab.c | 3 ++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/rtnetlink.h b/include/uapi/linux/rtnetlink.h
index 564790e854f7..cd1afb900929 100644
--- a/include/uapi/linux/rtnetlink.h
+++ b/include/uapi/linux/rtnetlink.h
@@ -146,6 +146,9 @@ enum {
RTM_GETSTATS = 94,
#define RTM_GETSTATS RTM_GETSTATS
+ RTM_NEWCACHEREPORT = 96,
+#define RTM_NEWCACHEREPORT RTM_NEWCACHEREPORT
+
__RTM_MAX,
#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1)
};
diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c
index 5aeaf30b7a13..7b7433a1a34c 100644
--- a/security/selinux/nlmsgtab.c
+++ b/security/selinux/nlmsgtab.c
@@ -79,6 +79,7 @@ static const struct nlmsg_perm nlmsg_route_perms[] =
{ RTM_GETNSID, NETLINK_ROUTE_SOCKET__NLMSG_READ },
{ RTM_NEWSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ },
{ RTM_GETSTATS, NETLINK_ROUTE_SOCKET__NLMSG_READ },
+ { RTM_NEWCACHEREPORT, NETLINK_ROUTE_SOCKET__NLMSG_READ },
};
static const struct nlmsg_perm nlmsg_tcpdiag_perms[] =
@@ -158,7 +159,7 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)
switch (sclass) {
case SECCLASS_NETLINK_ROUTE_SOCKET:
/* RTM_MAX always point to RTM_SETxxxx, ie RTM_NEWxxx + 3 */
- BUILD_BUG_ON(RTM_MAX != (RTM_NEWSTATS + 3));
+ BUILD_BUG_ON(RTM_MAX != (RTM_NEWCACHEREPORT + 3));
err = nlmsg_perm(nlmsg_type, perm, nlmsg_route_perms,
sizeof(nlmsg_route_perms));
break;
--
2.13.1
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH net-next 2/3] ipmr: add netlink notifications on igmpmsg cache reports
2017-06-13 17:08 [PATCH net-next 0/3] ipmr/ip6mr: add Netlink notifications on cache reports Julien Gomes
2017-06-13 17:08 ` [PATCH net-next 1/3] rtnetlink: add NEWCACHEREPORT message type Julien Gomes
@ 2017-06-13 17:08 ` Julien Gomes
2017-06-14 7:56 ` Nicolas Dichtel
2017-06-13 17:08 ` [PATCH net-next 3/3] ip6mr: add netlink notifications on mrt6msg " Julien Gomes
2 siblings, 1 reply; 6+ messages in thread
From: Julien Gomes @ 2017-06-13 17:08 UTC (permalink / raw)
To: davem; +Cc: netdev, linux-kernel, nikolay, Julien Gomes
Add Netlink notifications on cache reports in ipmr, in addition to the
existing igmpmsg sent to mroute_sk.
Send RTM_NEWCACHEREPORT notifications to RTNLGRP_IPV4_MROUTE.
MSGTYPE, VIF_ID, SRC_ADDR and DST_ADDR Netlink attributes contain the
same data as their equivalent fields in the igmpmsg header.
PKT attribute is the packet sent to mroute_sk, without the added igmpmsg
header.
Suggested-by: Ryan Halbrook <halbrook@arista.com>
Signed-off-by: Julien Gomes <julien@arista.com>
---
include/uapi/linux/mroute.h | 11 ++++++++
net/ipv4/ipmr.c | 63 +++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/include/uapi/linux/mroute.h b/include/uapi/linux/mroute.h
index f904367c0cee..f6f9e01ee734 100644
--- a/include/uapi/linux/mroute.h
+++ b/include/uapi/linux/mroute.h
@@ -152,6 +152,17 @@ enum {
};
#define IPMRA_VIFA_MAX (__IPMRA_VIFA_MAX - 1)
+/* ipmr netlink cache report attributes */
+enum {
+ IPMRA_CACHEREPORTA_MSGTYPE,
+ IPMRA_CACHEREPORTA_VIF_ID,
+ IPMRA_CACHEREPORTA_SRC_ADDR,
+ IPMRA_CACHEREPORTA_DST_ADDR,
+ IPMRA_CACHEREPORTA_PKT,
+ __IPMRA_CACHEREPORTA_MAX
+};
+#define IPMRA_CACHEREPORTA_MAX (__IPMRA_CACHEREPORTA_MAX - 1)
+
/* That's all usermode folks */
#define MFC_ASSERT_THRESH (3*HZ) /* Maximal freq. of asserts */
diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 9374b99c7c17..6d1f4fae3749 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -109,6 +109,7 @@ static int __ipmr_fill_mroute(struct mr_table *mrt, struct sk_buff *skb,
struct mfc_cache *c, struct rtmsg *rtm);
static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc,
int cmd);
+static void igmpmsg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt);
static void mroute_clean_tables(struct mr_table *mrt, bool all);
static void ipmr_expire_process(unsigned long arg);
@@ -993,8 +994,7 @@ static void ipmr_cache_resolve(struct net *net, struct mr_table *mrt,
}
}
-/* Bounce a cache query up to mrouted. We could use netlink for this but mrouted
- * expects the following bizarre scheme.
+/* Bounce a cache query up to mrouted and netlink.
*
* Called under mrt_lock.
*/
@@ -1060,6 +1060,8 @@ static int ipmr_cache_report(struct mr_table *mrt,
return -EINVAL;
}
+ igmpmsg_netlink_event(mrt, skb);
+
/* Deliver to mrouted */
ret = sock_queue_rcv_skb(mroute_sk, skb);
rcu_read_unlock();
@@ -2341,6 +2343,63 @@ static void mroute_netlink_event(struct mr_table *mrt, struct mfc_cache *mfc,
rtnl_set_sk_err(net, RTNLGRP_IPV4_MROUTE, err);
}
+static void igmpmsg_netlink_event(struct mr_table *mrt, struct sk_buff *pkt)
+{
+ struct net *net = read_pnet(&mrt->net);
+ struct nlmsghdr *nlh;
+ struct rtgenmsg *rtgenm;
+ struct igmpmsg *msg;
+ struct sk_buff *skb;
+ int payloadlen;
+ int msgsize;
+
+ payloadlen = pkt->len - sizeof(struct igmpmsg);
+ msg = (struct igmpmsg *)skb_network_header(pkt);
+ msgsize = NLMSG_ALIGN(sizeof(struct rtgenmsg))
+ + nla_total_size(1)
+ /* IPMRA_CACHEREPORTA_MSGTYPE */
+ + nla_total_size(1)
+ /* IPMRA_CACHEREPORTA_VIF_ID */
+ + nla_total_size(4)
+ /* IPMRA_CACHEREPORTA_SRC_ADDR */
+ + nla_total_size(4)
+ /* IPMRA_CACHEREPORTA_DST_ADDR */
+ + nla_total_size(payloadlen)
+ /* IPMRA_CACHEREPORTA_PKT */
+ ;
+
+ skb = nlmsg_new(msgsize, GFP_ATOMIC);
+ if (!skb)
+ goto errout;
+
+ nlh = nlmsg_put(skb, 0, 0, RTM_NEWCACHEREPORT,
+ sizeof(struct rtgenmsg), 0);
+ if (!nlh)
+ goto errout;
+ rtgenm = nlmsg_data(nlh);
+ rtgenm->rtgen_family = RTNL_FAMILY_IPMR;
+ if (nla_put_u8(skb, IPMRA_CACHEREPORTA_MSGTYPE, msg->im_msgtype) ||
+ nla_put_u8(skb, IPMRA_CACHEREPORTA_VIF_ID, msg->im_vif) ||
+ nla_put_in_addr(skb, IPMRA_CACHEREPORTA_SRC_ADDR,
+ msg->im_src.s_addr) ||
+ nla_put_in_addr(skb, IPMRA_CACHEREPORTA_DST_ADDR,
+ msg->im_dst.s_addr) ||
+ nla_put(skb, IPMRA_CACHEREPORTA_PKT, payloadlen,
+ pkt->data + sizeof(struct igmpmsg)))
+ goto nla_put_failure;
+
+ nlmsg_end(skb, nlh);
+
+ rtnl_notify(skb, net, 0, RTNLGRP_IPV4_MROUTE, NULL, GFP_ATOMIC);
+ return;
+
+nla_put_failure:
+ nlmsg_cancel(skb, nlh);
+errout:
+ kfree_skb(skb);
+ rtnl_set_sk_err(net, RTNLGRP_IPV4_MROUTE, -ENOBUFS);
+}
+
static int ipmr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
{
struct net *net = sock_net(skb->sk);
--
2.13.1
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH net-next 2/3] ipmr: add netlink notifications on igmpmsg cache reports
2017-06-13 17:08 ` [PATCH net-next 2/3] ipmr: add netlink notifications on igmpmsg cache reports Julien Gomes
@ 2017-06-14 7:56 ` Nicolas Dichtel
2017-06-14 21:08 ` Julien Gomes
0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Dichtel @ 2017-06-14 7:56 UTC (permalink / raw)
To: Julien Gomes, davem; +Cc: netdev, linux-kernel, nikolay
Le 13/06/2017 à 19:08, Julien Gomes a écrit :
> Add Netlink notifications on cache reports in ipmr, in addition to the
> existing igmpmsg sent to mroute_sk.
> Send RTM_NEWCACHEREPORT notifications to RTNLGRP_IPV4_MROUTE.
>
> MSGTYPE, VIF_ID, SRC_ADDR and DST_ADDR Netlink attributes contain the
> same data as their equivalent fields in the igmpmsg header.
> PKT attribute is the packet sent to mroute_sk, without the added igmpmsg
> header.
>
> Suggested-by: Ryan Halbrook <halbrook@arista.com>
> Signed-off-by: Julien Gomes <julien@arista.com>
> ---
> include/uapi/linux/mroute.h | 11 ++++++++
> net/ipv4/ipmr.c | 63 +++++++++++++++++++++++++++++++++++++++++++--
> 2 files changed, 72 insertions(+), 2 deletions(-)
>
> diff --git a/include/uapi/linux/mroute.h b/include/uapi/linux/mroute.h
> index f904367c0cee..f6f9e01ee734 100644
> --- a/include/uapi/linux/mroute.h
> +++ b/include/uapi/linux/mroute.h
> @@ -152,6 +152,17 @@ enum {
> };
> #define IPMRA_VIFA_MAX (__IPMRA_VIFA_MAX - 1)
>
> +/* ipmr netlink cache report attributes */
> +enum {
IPMRA_CACHEREPORTA_UNSPEC is missing.
By the way, maybe something shorter than IPMRA_CACHEREPORTA_ would be better.
What about IPMR_CREPORTA_? IPMR_CACHEA_? IPMR_IGMPA_? or whatever.
What is the signification of the two 'A'? One for 'attribute', but the other?
> + IPMRA_CACHEREPORTA_MSGTYPE,
> + IPMRA_CACHEREPORTA_VIF_ID,
> + IPMRA_CACHEREPORTA_SRC_ADDR,
> + IPMRA_CACHEREPORTA_DST_ADDR,
> + IPMRA_CACHEREPORTA_PKT,
> + __IPMRA_CACHEREPORTA_MAX
> +};
> +#define IPMRA_CACHEREPORTA_MAX (__IPMRA_CACHEREPORTA_MAX - 1)
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH net-next 2/3] ipmr: add netlink notifications on igmpmsg cache reports
2017-06-14 7:56 ` Nicolas Dichtel
@ 2017-06-14 21:08 ` Julien Gomes
0 siblings, 0 replies; 6+ messages in thread
From: Julien Gomes @ 2017-06-14 21:08 UTC (permalink / raw)
To: nicolas.dichtel, davem; +Cc: netdev, linux-kernel, nikolay
On 06/14/2017 12:56 AM, Nicolas Dichtel wrote:
> Le 13/06/2017 à 19:08, Julien Gomes a écrit :
>> Add Netlink notifications on cache reports in ipmr, in addition to the
>> existing igmpmsg sent to mroute_sk.
>> Send RTM_NEWCACHEREPORT notifications to RTNLGRP_IPV4_MROUTE.
>>
>> MSGTYPE, VIF_ID, SRC_ADDR and DST_ADDR Netlink attributes contain the
>> same data as their equivalent fields in the igmpmsg header.
>> PKT attribute is the packet sent to mroute_sk, without the added igmpmsg
>> header.
>>
>> Suggested-by: Ryan Halbrook <halbrook@arista.com>
>> Signed-off-by: Julien Gomes <julien@arista.com>
>> ---
>> include/uapi/linux/mroute.h | 11 ++++++++
>> net/ipv4/ipmr.c | 63 +++++++++++++++++++++++++++++++++++++++++++--
>> 2 files changed, 72 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/uapi/linux/mroute.h b/include/uapi/linux/mroute.h
>> index f904367c0cee..f6f9e01ee734 100644
>> --- a/include/uapi/linux/mroute.h
>> +++ b/include/uapi/linux/mroute.h
>> @@ -152,6 +152,17 @@ enum {
>> };
>> #define IPMRA_VIFA_MAX (__IPMRA_VIFA_MAX - 1)
>>
>> +/* ipmr netlink cache report attributes */
>> +enum {
> IPMRA_CACHEREPORTA_UNSPEC is missing.
Indeed, I will add it.
> By the way, maybe something shorter than IPMRA_CACHEREPORTA_ would be better.
> What about IPMR_CREPORTA_? IPMR_CACHEA_? IPMR_IGMPA_? or whatever.
I see absolutely no issue in shortening them.
IPMRA_CREPORT_ sounds good to me.
> What is the signification of the two 'A'? One for 'attribute', but the other?
Now that you mention it, the second 'A' is simply redundant.
I will remove it and go with IPMRA_CREPORT_.
--
Julien Gomes
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH net-next 3/3] ip6mr: add netlink notifications on mrt6msg cache reports
2017-06-13 17:08 [PATCH net-next 0/3] ipmr/ip6mr: add Netlink notifications on cache reports Julien Gomes
2017-06-13 17:08 ` [PATCH net-next 1/3] rtnetlink: add NEWCACHEREPORT message type Julien Gomes
2017-06-13 17:08 ` [PATCH net-next 2/3] ipmr: add netlink notifications on igmpmsg cache reports Julien Gomes
@ 2017-06-13 17:08 ` Julien Gomes
2 siblings, 0 replies; 6+ messages in thread
From: Julien Gomes @ 2017-06-13 17:08 UTC (permalink / raw)
To: davem; +Cc: netdev, linux-kernel, nikolay, Julien Gomes
Add Netlink notifications on cache reports in ip6mr, in addition to the
existing mrt6msg sent to mroute6_sk.
Send RTM_NEWCACHEREPORT notifications to RTNLGRP_IPV6_MROUTE.
MSGTYPE, MIF_ID, SRC_ADDR and DST_ADDR Netlink attributes contain the
same data as their equivalent fields in the mrt6msg header.
PKT attribute is the packet sent to mroute6_sk, without the added
mrt6msg header.
Suggested-by: Ryan Halbrook <halbrook@arista.com>
Signed-off-by: Julien Gomes <julien@arista.com>
---
include/uapi/linux/mroute6.h | 11 ++++++++
net/ipv6/ip6mr.c | 63 ++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 72 insertions(+), 2 deletions(-)
diff --git a/include/uapi/linux/mroute6.h b/include/uapi/linux/mroute6.h
index ed5721148768..8e3c2d2c170e 100644
--- a/include/uapi/linux/mroute6.h
+++ b/include/uapi/linux/mroute6.h
@@ -133,4 +133,15 @@ struct mrt6msg {
struct in6_addr im6_src, im6_dst;
};
+/* ip6mr netlink cache report attributes */
+enum {
+ IP6MRA_CACHEREPORTA_MSGTYPE,
+ IP6MRA_CACHEREPORTA_MIF_ID,
+ IP6MRA_CACHEREPORTA_SRC_ADDR,
+ IP6MRA_CACHEREPORTA_DST_ADDR,
+ IP6MRA_CACHEREPORTA_PKT,
+ __IP6MRA_CACHEREPORTA_MAX
+};
+#define IP6MRA_CACHEREPORTA_MAX (__IP6MRA_CACHEREPORTA_MAX - 1)
+
#endif /* _UAPI__LINUX_MROUTE6_H */
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 374997d26488..8667256b4343 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -116,6 +116,7 @@ static int __ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
struct mfc6_cache *c, struct rtmsg *rtm);
static void mr6_netlink_event(struct mr6_table *mrt, struct mfc6_cache *mfc,
int cmd);
+static void mrt6msg_netlink_event(struct mr6_table *mrt, struct sk_buff *pkt);
static int ip6mr_rtm_dumproute(struct sk_buff *skb,
struct netlink_callback *cb);
static void mroute_clean_tables(struct mr6_table *mrt, bool all);
@@ -1123,8 +1124,7 @@ static void ip6mr_cache_resolve(struct net *net, struct mr6_table *mrt,
}
/*
- * Bounce a cache query up to pim6sd. We could use netlink for this but pim6sd
- * expects the following bizarre scheme.
+ * Bounce a cache query up to pim6sd and netlink.
*
* Called under mrt_lock.
*/
@@ -1206,6 +1206,8 @@ static int ip6mr_cache_report(struct mr6_table *mrt, struct sk_buff *pkt,
return -EINVAL;
}
+ mrt6msg_netlink_event(mrt, skb);
+
/*
* Deliver to user space multicast routing algorithms
*/
@@ -2455,6 +2457,63 @@ static void mr6_netlink_event(struct mr6_table *mrt, struct mfc6_cache *mfc,
rtnl_set_sk_err(net, RTNLGRP_IPV6_MROUTE, err);
}
+static void mrt6msg_netlink_event(struct mr6_table *mrt, struct sk_buff *pkt)
+{
+ struct net *net = read_pnet(&mrt->net);
+ struct nlmsghdr *nlh;
+ struct rtgenmsg *rtgenm;
+ struct mrt6msg *msg;
+ struct sk_buff *skb;
+ int payloadlen;
+ int msgsize;
+
+ payloadlen = pkt->len - sizeof(struct mrt6msg);
+ msg = (struct mrt6msg *)skb_transport_header(pkt);
+ msgsize = NLMSG_ALIGN(sizeof(struct rtgenmsg))
+ + nla_total_size(1)
+ /* IP6MRA_CACHEREPORTA_MSGTYPE */
+ + nla_total_size(2)
+ /* IP6MRA_CACHEREPORTA_MIF_ID */
+ + nla_total_size(sizeof(struct in6_addr))
+ /* IP6MRA_CACHEREPORTA_SRC_ADDR */
+ + nla_total_size(sizeof(struct in6_addr))
+ /* IP6MRA_CACHEREPORTA_DST_ADDR */
+ + nla_total_size(payloadlen)
+ /* IP6MRA_CACHEREPORTA_PKT */
+ ;
+
+ skb = nlmsg_new(msgsize, GFP_ATOMIC);
+ if (!skb)
+ goto errout;
+
+ nlh = nlmsg_put(skb, 0, 0, RTM_NEWCACHEREPORT,
+ sizeof(struct rtgenmsg), 0);
+ if (!nlh)
+ goto errout;
+ rtgenm = nlmsg_data(nlh);
+ rtgenm->rtgen_family = RTNL_FAMILY_IP6MR;
+ if (nla_put_u8(skb, IP6MRA_CACHEREPORTA_MSGTYPE, msg->im6_msgtype) ||
+ nla_put_u16(skb, IP6MRA_CACHEREPORTA_MIF_ID, msg->im6_mif) ||
+ nla_put_in6_addr(skb, IP6MRA_CACHEREPORTA_SRC_ADDR,
+ &msg->im6_src) ||
+ nla_put_in6_addr(skb, IP6MRA_CACHEREPORTA_DST_ADDR,
+ &msg->im6_dst) ||
+ nla_put(skb, IP6MRA_CACHEREPORTA_PKT, payloadlen,
+ pkt->data + sizeof(struct mrt6msg)))
+ goto nla_put_failure;
+
+ nlmsg_end(skb, nlh);
+
+ rtnl_notify(skb, net, 0, RTNLGRP_IPV6_MROUTE, NULL, GFP_ATOMIC);
+ return;
+
+nla_put_failure:
+ nlmsg_cancel(skb, nlh);
+errout:
+ kfree_skb(skb);
+ rtnl_set_sk_err(net, RTNLGRP_IPV6_MROUTE, -ENOBUFS);
+}
+
static int ip6mr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
{
struct net *net = sock_net(skb->sk);
--
2.13.1
^ permalink raw reply [flat|nested] 6+ messages in thread