1
0
Fork 0
mirror of synced 2025-03-06 20:59:54 +01:00

mctp: Specify route types, require rtm_type in RTM_*ROUTE messages

This change adds a 'type' attribute to routes, which can be parsed from
a RTM_NEWROUTE message. This will help to distinguish local vs. peer
routes in a future change.

This means userspace will need to set a correct rtm_type in RTM_NEWROUTE
and RTM_DELROUTE messages; we currently only accept RTN_UNICAST.

Signed-off-by: Jeremy Kerr <jk@codeconstruct.com.au>
Link: https://lore.kernel.org/r/20210810023834.2231088-1-jk@codeconstruct.com.au
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Jeremy Kerr 2021-08-10 10:38:34 +08:00 committed by Jakub Kicinski
parent ddccc5e368
commit 83f0a0b728
2 changed files with 23 additions and 5 deletions

View file

@ -173,6 +173,7 @@ struct mctp_route {
struct mctp_dev *dev; struct mctp_dev *dev;
unsigned int mtu; unsigned int mtu;
unsigned char type;
int (*output)(struct mctp_route *route, int (*output)(struct mctp_route *route,
struct sk_buff *skb); struct sk_buff *skb);

View file

@ -710,8 +710,9 @@ int mctp_local_output(struct sock *sk, struct mctp_route *rt,
/* route management */ /* route management */
static int mctp_route_add(struct mctp_dev *mdev, mctp_eid_t daddr_start, static int mctp_route_add(struct mctp_dev *mdev, mctp_eid_t daddr_start,
unsigned int daddr_extent, unsigned int mtu, unsigned int daddr_extent, unsigned int mtu,
bool is_local) unsigned char type)
{ {
int (*rtfn)(struct mctp_route *rt, struct sk_buff *skb);
struct net *net = dev_net(mdev->dev); struct net *net = dev_net(mdev->dev);
struct mctp_route *rt, *ert; struct mctp_route *rt, *ert;
@ -721,6 +722,17 @@ static int mctp_route_add(struct mctp_dev *mdev, mctp_eid_t daddr_start,
if (daddr_extent > 0xff || daddr_start + daddr_extent >= 255) if (daddr_extent > 0xff || daddr_start + daddr_extent >= 255)
return -EINVAL; return -EINVAL;
switch (type) {
case RTN_LOCAL:
rtfn = mctp_route_input;
break;
case RTN_UNICAST:
rtfn = mctp_route_output;
break;
default:
return -EINVAL;
}
rt = mctp_route_alloc(); rt = mctp_route_alloc();
if (!rt) if (!rt)
return -ENOMEM; return -ENOMEM;
@ -730,7 +742,8 @@ static int mctp_route_add(struct mctp_dev *mdev, mctp_eid_t daddr_start,
rt->mtu = mtu; rt->mtu = mtu;
rt->dev = mdev; rt->dev = mdev;
dev_hold(rt->dev->dev); dev_hold(rt->dev->dev);
rt->output = is_local ? mctp_route_input : mctp_route_output; rt->type = type;
rt->output = rtfn;
ASSERT_RTNL(); ASSERT_RTNL();
/* Prevent duplicate identical routes. */ /* Prevent duplicate identical routes. */
@ -777,7 +790,7 @@ static int mctp_route_remove(struct mctp_dev *mdev, mctp_eid_t daddr_start,
int mctp_route_add_local(struct mctp_dev *mdev, mctp_eid_t addr) int mctp_route_add_local(struct mctp_dev *mdev, mctp_eid_t addr)
{ {
return mctp_route_add(mdev, addr, 0, 0, true); return mctp_route_add(mdev, addr, 0, 0, RTN_LOCAL);
} }
int mctp_route_remove_local(struct mctp_dev *mdev, mctp_eid_t addr) int mctp_route_remove_local(struct mctp_dev *mdev, mctp_eid_t addr)
@ -936,7 +949,11 @@ static int mctp_newroute(struct sk_buff *skb, struct nlmsghdr *nlh,
/* TODO: parse mtu from nlparse */ /* TODO: parse mtu from nlparse */
mtu = 0; mtu = 0;
rc = mctp_route_add(mdev, daddr_start, rtm->rtm_dst_len, mtu, false); if (rtm->rtm_type != RTN_UNICAST)
return -EINVAL;
rc = mctp_route_add(mdev, daddr_start, rtm->rtm_dst_len, mtu,
rtm->rtm_type);
return rc; return rc;
} }
@ -985,7 +1002,7 @@ static int mctp_fill_rtinfo(struct sk_buff *skb, struct mctp_route *rt,
hdr->rtm_table = RT_TABLE_DEFAULT; hdr->rtm_table = RT_TABLE_DEFAULT;
hdr->rtm_protocol = RTPROT_STATIC; /* everything is user-defined */ hdr->rtm_protocol = RTPROT_STATIC; /* everything is user-defined */
hdr->rtm_scope = RT_SCOPE_LINK; /* TODO: scope in mctp_route? */ hdr->rtm_scope = RT_SCOPE_LINK; /* TODO: scope in mctp_route? */
hdr->rtm_type = RTN_ANYCAST; /* TODO: type from route */ hdr->rtm_type = rt->type;
if (nla_put_u8(skb, RTA_DST, rt->min)) if (nla_put_u8(skb, RTA_DST, rt->min))
goto cancel; goto cancel;