Commit 75c4a57c authored by David S. Miller's avatar David S. Miller

Merge branch 'ipmr-nl'

Nikolay Aleksandrov says:

====================
net: ipmr: more cleanups and mfc netlink support

This set continues with the minor cleanups in the first 6 patches and
patch 7 adds the first new feature - MFC manipulation via netlink. It
registers NEWROUTE/DELROUTE for that purpose and uses the same semantics
as the already present netlink dump. The only new attribute that is used
is RTA_PREFSRC to denote an MFC_PROXY entry. Currently the table must
exist before adding an entry, and new tables can be created only via
setsockopt, but that will be changed in the future.
This set was tested with modified iproute2 which supports NEWROUTE/DELROUTE
for RTNL_FAMILY_IPMR.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 43cd6991 ccbb0aa6
...@@ -9,38 +9,28 @@ ...@@ -9,38 +9,28 @@
#ifdef CONFIG_IP_MROUTE #ifdef CONFIG_IP_MROUTE
static inline int ip_mroute_opt(int opt) static inline int ip_mroute_opt(int opt)
{ {
return (opt >= MRT_BASE) && (opt <= MRT_MAX); return opt >= MRT_BASE && opt <= MRT_MAX;
} }
#else
static inline int ip_mroute_opt(int opt)
{
return 0;
}
#endif
#ifdef CONFIG_IP_MROUTE int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int);
extern int ip_mroute_setsockopt(struct sock *, int, char __user *, unsigned int); int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *);
extern int ip_mroute_getsockopt(struct sock *, int, char __user *, int __user *); int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg);
extern int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg); int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg);
extern int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg); int ip_mr_init(void);
extern int ip_mr_init(void);
#else #else
static inline static inline int ip_mroute_setsockopt(struct sock *sock, int optname,
int ip_mroute_setsockopt(struct sock *sock, char __user *optval, unsigned int optlen)
int optname, char __user *optval, unsigned int optlen)
{ {
return -ENOPROTOOPT; return -ENOPROTOOPT;
} }
static inline static inline int ip_mroute_getsockopt(struct sock *sock, int optname,
int ip_mroute_getsockopt(struct sock *sock, char __user *optval, int __user *optlen)
int optname, char __user *optval, int __user *optlen)
{ {
return -ENOPROTOOPT; return -ENOPROTOOPT;
} }
static inline static inline int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
{ {
return -ENOIOCTLCMD; return -ENOIOCTLCMD;
} }
...@@ -49,6 +39,11 @@ static inline int ip_mr_init(void) ...@@ -49,6 +39,11 @@ static inline int ip_mr_init(void)
{ {
return 0; return 0;
} }
static inline int ip_mroute_opt(int opt)
{
return 0;
}
#endif #endif
struct vif_device { struct vif_device {
...@@ -64,6 +59,32 @@ struct vif_device { ...@@ -64,6 +59,32 @@ struct vif_device {
#define VIFF_STATIC 0x8000 #define VIFF_STATIC 0x8000
#define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
#define MFC_LINES 64
struct mr_table {
struct list_head list;
possible_net_t net;
u32 id;
struct sock __rcu *mroute_sk;
struct timer_list ipmr_expire_timer;
struct list_head mfc_unres_queue;
struct list_head mfc_cache_array[MFC_LINES];
struct vif_device vif_table[MAXVIFS];
int maxvif;
atomic_t cache_resolve_queue_len;
bool mroute_do_assert;
bool mroute_do_pim;
int mroute_reg_vif_num;
};
/* mfc_flags:
* MFC_STATIC - the entry was added statically (not by a routing daemon)
*/
enum {
MFC_STATIC = BIT(0),
};
struct mfc_cache { struct mfc_cache {
struct list_head list; struct list_head list;
__be32 mfc_mcastgrp; /* Group the entry belongs to */ __be32 mfc_mcastgrp; /* Group the entry belongs to */
...@@ -89,11 +110,6 @@ struct mfc_cache { ...@@ -89,11 +110,6 @@ struct mfc_cache {
struct rcu_head rcu; struct rcu_head rcu;
}; };
#define MFC_STATIC 1
#define MFC_NOTIFY 2
#define MFC_LINES 64
#ifdef __BIG_ENDIAN #ifdef __BIG_ENDIAN
#define MFC_HASH(a,b) (((((__force u32)(__be32)a)>>24)^(((__force u32)(__be32)b)>>26))&(MFC_LINES-1)) #define MFC_HASH(a,b) (((((__force u32)(__be32)a)>>24)^(((__force u32)(__be32)b)>>26))&(MFC_LINES-1))
#else #else
...@@ -101,7 +117,7 @@ struct mfc_cache { ...@@ -101,7 +117,7 @@ struct mfc_cache {
#endif #endif
struct rtmsg; struct rtmsg;
extern int ipmr_get_route(struct net *net, struct sk_buff *skb, int ipmr_get_route(struct net *net, struct sk_buff *skb,
__be32 saddr, __be32 daddr, __be32 saddr, __be32 daddr,
struct rtmsg *rtm, int nowait); struct rtmsg *rtm, int nowait);
#endif #endif
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
#define PIM_NULL_REGISTER cpu_to_be32(0x40000000) #define PIM_NULL_REGISTER cpu_to_be32(0x40000000)
static inline bool ipmr_pimsm_enabled(void)
{
return IS_BUILTIN(CONFIG_IP_PIMSM_V1) || IS_BUILTIN(CONFIG_IP_PIMSM_V2);
}
/* PIMv2 register message header layout (ietf-draft-idmr-pimvsm-v2-00.ps */ /* PIMv2 register message header layout (ietf-draft-idmr-pimvsm-v2-00.ps */
struct pimreghdr struct pimreghdr
{ {
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <linux/tcp.h> #include <linux/tcp.h>
#include <linux/udp.h> #include <linux/udp.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/mroute.h>
#include <linux/if_vlan.h> #include <linux/if_vlan.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/in6.h> #include <linux/in6.h>
......
...@@ -76,7 +76,6 @@ ...@@ -76,7 +76,6 @@
#include <linux/igmp.h> #include <linux/igmp.h>
#include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv4.h>
#include <linux/netfilter_bridge.h> #include <linux/netfilter_bridge.h>
#include <linux/mroute.h>
#include <linux/netlink.h> #include <linux/netlink.h>
#include <linux/tcp.h> #include <linux/tcp.h>
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <linux/tcp.h> #include <linux/tcp.h>
#include <linux/udp.h> #include <linux/udp.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/mroute.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/in6.h> #include <linux/in6.h>
#include <linux/inetdevice.h> #include <linux/inetdevice.h>
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/in.h> #include <linux/in.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/mroute.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/in6.h> #include <linux/in6.h>
#include <linux/inetdevice.h> #include <linux/inetdevice.h>
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
#include <linux/tcp.h> #include <linux/tcp.h>
#include <linux/udp.h> #include <linux/udp.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/mroute.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv4.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
......
...@@ -103,7 +103,6 @@ ...@@ -103,7 +103,6 @@
#include <linux/tcp.h> #include <linux/tcp.h>
#include <linux/udp.h> #include <linux/udp.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/mroute.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/netfilter_ipv4.h> #include <linux/netfilter_ipv4.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
......
...@@ -66,22 +66,7 @@ ...@@ -66,22 +66,7 @@
#include <net/netlink.h> #include <net/netlink.h>
#include <net/fib_rules.h> #include <net/fib_rules.h>
#include <linux/netconf.h> #include <linux/netconf.h>
#include <net/nexthop.h>
struct mr_table {
struct list_head list;
possible_net_t net;
u32 id;
struct sock __rcu *mroute_sk;
struct timer_list ipmr_expire_timer;
struct list_head mfc_unres_queue;
struct list_head mfc_cache_array[MFC_LINES];
struct vif_device vif_table[MAXVIFS];
int maxvif;
atomic_t cache_resolve_queue_len;
bool mroute_do_assert;
bool mroute_do_pim;
int mroute_reg_vif_num;
};
struct ipmr_rule { struct ipmr_rule {
struct fib_rule common; struct fib_rule common;
...@@ -91,11 +76,6 @@ struct ipmr_result { ...@@ -91,11 +76,6 @@ struct ipmr_result {
struct mr_table *mrt; struct mr_table *mrt;
}; };
static inline bool pimsm_enabled(void)
{
return IS_BUILTIN(CONFIG_IP_PIMSM_V1) || IS_BUILTIN(CONFIG_IP_PIMSM_V2);
}
/* Big lock, protecting vif table, mrt cache and mroute socket state. /* Big lock, protecting vif table, mrt cache and mroute socket state.
* Note that the changes are semaphored via rtnl_lock. * Note that the changes are semaphored via rtnl_lock.
*/ */
...@@ -104,8 +84,6 @@ static DEFINE_RWLOCK(mrt_lock); ...@@ -104,8 +84,6 @@ static DEFINE_RWLOCK(mrt_lock);
/* Multicast router control variables */ /* Multicast router control variables */
#define VIF_EXISTS(_mrt, _idx) ((_mrt)->vif_table[_idx].dev != NULL)
/* Special spinlock for queue of unresolved entries */ /* Special spinlock for queue of unresolved entries */
static DEFINE_SPINLOCK(mfc_unres_lock); static DEFINE_SPINLOCK(mfc_unres_lock);
...@@ -769,7 +747,7 @@ static int vif_add(struct net *net, struct mr_table *mrt, ...@@ -769,7 +747,7 @@ static int vif_add(struct net *net, struct mr_table *mrt,
switch (vifc->vifc_flags) { switch (vifc->vifc_flags) {
case VIFF_REGISTER: case VIFF_REGISTER:
if (!pimsm_enabled()) if (!ipmr_pimsm_enabled())
return -EINVAL; return -EINVAL;
/* Special Purpose VIF in PIM /* Special Purpose VIF in PIM
* All the packets will be sent to the daemon * All the packets will be sent to the daemon
...@@ -1307,12 +1285,14 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, ...@@ -1307,12 +1285,14 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval,
switch (optname) { switch (optname) {
case MRT_INIT: case MRT_INIT:
if (optlen != sizeof(int)) if (optlen != sizeof(int)) {
ret = -EINVAL; ret = -EINVAL;
if (rtnl_dereference(mrt->mroute_sk)) break;
}
if (rtnl_dereference(mrt->mroute_sk)) {
ret = -EADDRINUSE; ret = -EADDRINUSE;
if (ret)
break; break;
}
ret = ip_ra_control(sk, 1, mrtsock_destruct); ret = ip_ra_control(sk, 1, mrtsock_destruct);
if (ret == 0) { if (ret == 0) {
...@@ -1395,7 +1375,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, ...@@ -1395,7 +1375,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval,
mrt->mroute_do_assert = val; mrt->mroute_do_assert = val;
break; break;
case MRT_PIM: case MRT_PIM:
if (!pimsm_enabled()) { if (!ipmr_pimsm_enabled()) {
ret = -ENOPROTOOPT; ret = -ENOPROTOOPT;
break; break;
} }
...@@ -1469,7 +1449,7 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int ...@@ -1469,7 +1449,7 @@ int ip_mroute_getsockopt(struct sock *sk, int optname, char __user *optval, int
val = 0x0305; val = 0x0305;
break; break;
case MRT_PIM: case MRT_PIM:
if (!pimsm_enabled()) if (!ipmr_pimsm_enabled())
return -ENOPROTOOPT; return -ENOPROTOOPT;
val = mrt->mroute_do_pim; val = mrt->mroute_do_pim;
break; break;
...@@ -2199,8 +2179,6 @@ int ipmr_get_route(struct net *net, struct sk_buff *skb, ...@@ -2199,8 +2179,6 @@ int ipmr_get_route(struct net *net, struct sk_buff *skb,
} }
read_lock(&mrt_lock); read_lock(&mrt_lock);
if (!nowait && (rtm->rtm_flags & RTM_F_NOTIFY))
cache->mfc_flags |= MFC_NOTIFY;
err = __ipmr_fill_mroute(mrt, skb, cache, rtm); err = __ipmr_fill_mroute(mrt, skb, cache, rtm);
read_unlock(&mrt_lock); read_unlock(&mrt_lock);
rcu_read_unlock(); rcu_read_unlock();
...@@ -2362,6 +2340,130 @@ static int ipmr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb) ...@@ -2362,6 +2340,130 @@ static int ipmr_rtm_dumproute(struct sk_buff *skb, struct netlink_callback *cb)
return skb->len; return skb->len;
} }
static const struct nla_policy rtm_ipmr_policy[RTA_MAX + 1] = {
[RTA_SRC] = { .type = NLA_U32 },
[RTA_DST] = { .type = NLA_U32 },
[RTA_IIF] = { .type = NLA_U32 },
[RTA_TABLE] = { .type = NLA_U32 },
[RTA_MULTIPATH] = { .len = sizeof(struct rtnexthop) },
};
static bool ipmr_rtm_validate_proto(unsigned char rtm_protocol)
{
switch (rtm_protocol) {
case RTPROT_STATIC:
case RTPROT_MROUTED:
return true;
}
return false;
}
static int ipmr_nla_get_ttls(const struct nlattr *nla, struct mfcctl *mfcc)
{
struct rtnexthop *rtnh = nla_data(nla);
int remaining = nla_len(nla), vifi = 0;
while (rtnh_ok(rtnh, remaining)) {
mfcc->mfcc_ttls[vifi] = rtnh->rtnh_hops;
if (++vifi == MAXVIFS)
break;
rtnh = rtnh_next(rtnh, &remaining);
}
return remaining > 0 ? -EINVAL : vifi;
}
/* returns < 0 on error, 0 for ADD_MFC and 1 for ADD_MFC_PROXY */
static int rtm_to_ipmr_mfcc(struct net *net, struct nlmsghdr *nlh,
struct mfcctl *mfcc, int *mrtsock,
struct mr_table **mrtret)
{
struct net_device *dev = NULL;
u32 tblid = RT_TABLE_DEFAULT;
struct mr_table *mrt;
struct nlattr *attr;
struct rtmsg *rtm;
int ret, rem;
ret = nlmsg_validate(nlh, sizeof(*rtm), RTA_MAX, rtm_ipmr_policy);
if (ret < 0)
goto out;
rtm = nlmsg_data(nlh);
ret = -EINVAL;
if (rtm->rtm_family != RTNL_FAMILY_IPMR || rtm->rtm_dst_len != 32 ||
rtm->rtm_type != RTN_MULTICAST ||
rtm->rtm_scope != RT_SCOPE_UNIVERSE ||
!ipmr_rtm_validate_proto(rtm->rtm_protocol))
goto out;
memset(mfcc, 0, sizeof(*mfcc));
mfcc->mfcc_parent = -1;
ret = 0;
nlmsg_for_each_attr(attr, nlh, sizeof(struct rtmsg), rem) {
switch (nla_type(attr)) {
case RTA_SRC:
mfcc->mfcc_origin.s_addr = nla_get_be32(attr);
break;
case RTA_DST:
mfcc->mfcc_mcastgrp.s_addr = nla_get_be32(attr);
break;
case RTA_IIF:
dev = __dev_get_by_index(net, nla_get_u32(attr));
if (!dev) {
ret = -ENODEV;
goto out;
}
break;
case RTA_MULTIPATH:
if (ipmr_nla_get_ttls(attr, mfcc) < 0) {
ret = -EINVAL;
goto out;
}
break;
case RTA_PREFSRC:
ret = 1;
break;
case RTA_TABLE:
tblid = nla_get_u32(attr);
break;
}
}
mrt = ipmr_get_table(net, tblid);
if (!mrt) {
ret = -ENOENT;
goto out;
}
*mrtret = mrt;
*mrtsock = rtm->rtm_protocol == RTPROT_MROUTED ? 1 : 0;
if (dev)
mfcc->mfcc_parent = ipmr_find_vif(mrt, dev);
out:
return ret;
}
/* takes care of both newroute and delroute */
static int ipmr_rtm_route(struct sk_buff *skb, struct nlmsghdr *nlh)
{
struct net *net = sock_net(skb->sk);
int ret, mrtsock, parent;
struct mr_table *tbl;
struct mfcctl mfcc;
mrtsock = 0;
tbl = NULL;
ret = rtm_to_ipmr_mfcc(net, nlh, &mfcc, &mrtsock, &tbl);
if (ret < 0)
return ret;
parent = ret ? mfcc.mfcc_parent : -1;
if (nlh->nlmsg_type == RTM_NEWROUTE)
return ipmr_mfc_add(net, tbl, &mfcc, mrtsock, parent);
else
return ipmr_mfc_delete(tbl, &mfcc, parent);
}
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
/* The /proc interfaces to multicast routing : /* The /proc interfaces to multicast routing :
* /proc/net/ip_mr_cache & /proc/net/ip_mr_vif * /proc/net/ip_mr_cache & /proc/net/ip_mr_vif
...@@ -2715,6 +2817,10 @@ int __init ip_mr_init(void) ...@@ -2715,6 +2817,10 @@ int __init ip_mr_init(void)
#endif #endif
rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE, rtnl_register(RTNL_FAMILY_IPMR, RTM_GETROUTE,
NULL, ipmr_rtm_dumproute, NULL); NULL, ipmr_rtm_dumproute, NULL);
rtnl_register(RTNL_FAMILY_IPMR, RTM_NEWROUTE,
ipmr_rtm_route, NULL, NULL);
rtnl_register(RTNL_FAMILY_IPMR, RTM_DELROUTE,
ipmr_rtm_route, NULL, NULL);
return 0; return 0;
#ifdef CONFIG_IP_PIMSM_V2 #ifdef CONFIG_IP_PIMSM_V2
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <linux/tcp.h> #include <linux/tcp.h>
#include <linux/udp.h> #include <linux/udp.h>
#include <linux/if_arp.h> #include <linux/if_arp.h>
#include <linux/mroute.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/in6.h> #include <linux/in6.h>
#include <linux/inetdevice.h> #include <linux/inetdevice.h>
......
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