Skip to content

Commit 65ee00a

Browse files
dsaherndavem330
authored andcommitted
net: nexthop uapi
New UAPI for nexthops as standalone objects: - defines netlink ancillary header, struct nhmsg - RTM commands for nexthop objects, RTM_*NEXTHOP, - RTNLGRP for nexthop notifications, RTNLGRP_NEXTHOP, - Attributes for creating nexthops, NHA_* - Attribute for route specs to specify a nexthop by id, RTA_NH_ID. The nexthop attributes and semantics follow the route and RTA ones for device, gateway and lwt encap. Unique to nexthop objects are a blackhole and a group which contains references to other nexthop objects. With the exception of blackhole and group, nexthop objects MUST contain a device. Gateway and encap are optional. Nexthop groups can only reference other pre-existing nexthops by id. If the NHA_ID attribute is present that id is used for the nexthop. If not specified, one is auto assigned. Dump requests can include attributes: - NHA_GROUPS to return only nexthop groups, - NHA_MASTER to limit dumps to nexthops with devices enslaved to the given master (e.g., VRF) - NHA_OIF to limit dumps to nexthops using given device nlmsg_route_perms in selinux code is updated for the new RTM comands. Signed-off-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 602e0f2 commit 65ee00a

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

include/uapi/linux/nexthop.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2+
#ifndef _UAPI_LINUX_NEXTHOP_H
3+
#define _UAPI_LINUX_NEXTHOP_H
4+
5+
#include <linux/types.h>
6+
7+
struct nhmsg {
8+
unsigned char nh_family;
9+
unsigned char nh_scope; /* return only */
10+
unsigned char nh_protocol; /* Routing protocol that installed nh */
11+
unsigned char resvd;
12+
unsigned int nh_flags; /* RTNH_F flags */
13+
};
14+
15+
/* entry in a nexthop group */
16+
struct nexthop_grp {
17+
__u32 id; /* nexthop id - must exist */
18+
__u8 weight; /* weight of this nexthop */
19+
__u8 resvd1;
20+
__u16 resvd2;
21+
};
22+
23+
enum {
24+
NEXTHOP_GRP_TYPE_MPATH, /* default type if not specified */
25+
__NEXTHOP_GRP_TYPE_MAX,
26+
};
27+
28+
#define NEXTHOP_GRP_TYPE_MAX (__NEXTHOP_GRP_TYPE_MAX - 1)
29+
30+
enum {
31+
NHA_UNSPEC,
32+
NHA_ID, /* u32; id for nexthop. id == 0 means auto-assign */
33+
34+
NHA_GROUP, /* array of nexthop_grp */
35+
NHA_GROUP_TYPE, /* u16 one of NEXTHOP_GRP_TYPE */
36+
/* if NHA_GROUP attribute is added, no other attributes can be set */
37+
38+
NHA_BLACKHOLE, /* flag; nexthop used to blackhole packets */
39+
/* if NHA_BLACKHOLE is added, OIF, GATEWAY, ENCAP can not be set */
40+
41+
NHA_OIF, /* u32; nexthop device */
42+
NHA_GATEWAY, /* be32 (IPv4) or in6_addr (IPv6) gw address */
43+
NHA_ENCAP_TYPE, /* u16; lwt encap type */
44+
NHA_ENCAP, /* lwt encap data */
45+
46+
/* NHA_OIF can be appended to dump request to return only
47+
* nexthops using given device
48+
*/
49+
NHA_GROUPS, /* flag; only return nexthop groups in dump */
50+
NHA_MASTER, /* u32; only return nexthops with given master dev */
51+
52+
__NHA_MAX,
53+
};
54+
55+
#define NHA_MAX (__NHA_MAX - 1)
56+
#endif

include/uapi/linux/rtnetlink.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ enum {
157157
RTM_GETCHAIN,
158158
#define RTM_GETCHAIN RTM_GETCHAIN
159159

160+
RTM_NEWNEXTHOP = 104,
161+
#define RTM_NEWNEXTHOP RTM_NEWNEXTHOP
162+
RTM_DELNEXTHOP,
163+
#define RTM_DELNEXTHOP RTM_DELNEXTHOP
164+
RTM_GETNEXTHOP,
165+
#define RTM_GETNEXTHOP RTM_GETNEXTHOP
166+
160167
__RTM_MAX,
161168
#define RTM_MAX (((__RTM_MAX + 3) & ~3) - 1)
162169
};
@@ -342,6 +349,7 @@ enum rtattr_type_t {
342349
RTA_IP_PROTO,
343350
RTA_SPORT,
344351
RTA_DPORT,
352+
RTA_NH_ID,
345353
__RTA_MAX
346354
};
347355

@@ -704,6 +712,8 @@ enum rtnetlink_groups {
704712
#define RTNLGRP_IPV4_MROUTE_R RTNLGRP_IPV4_MROUTE_R
705713
RTNLGRP_IPV6_MROUTE_R,
706714
#define RTNLGRP_IPV6_MROUTE_R RTNLGRP_IPV6_MROUTE_R
715+
RTNLGRP_NEXTHOP,
716+
#define RTNLGRP_NEXTHOP RTNLGRP_NEXTHOP
707717
__RTNLGRP_MAX
708718
};
709719
#define RTNLGRP_MAX (__RTNLGRP_MAX - 1)

security/selinux/nlmsgtab.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ static const struct nlmsg_perm nlmsg_route_perms[] =
8383
{ RTM_NEWCHAIN, NETLINK_ROUTE_SOCKET__NLMSG_WRITE },
8484
{ RTM_DELCHAIN, NETLINK_ROUTE_SOCKET__NLMSG_WRITE },
8585
{ RTM_GETCHAIN, NETLINK_ROUTE_SOCKET__NLMSG_READ },
86+
{ RTM_NEWNEXTHOP, NETLINK_ROUTE_SOCKET__NLMSG_WRITE },
87+
{ RTM_DELNEXTHOP, NETLINK_ROUTE_SOCKET__NLMSG_WRITE },
88+
{ RTM_GETNEXTHOP, NETLINK_ROUTE_SOCKET__NLMSG_READ },
8689
};
8790

8891
static const struct nlmsg_perm nlmsg_tcpdiag_perms[] =
@@ -166,7 +169,7 @@ int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm)
166169
* structures at the top of this file with the new mappings
167170
* before updating the BUILD_BUG_ON() macro!
168171
*/
169-
BUILD_BUG_ON(RTM_MAX != (RTM_NEWCHAIN + 3));
172+
BUILD_BUG_ON(RTM_MAX != (RTM_NEWNEXTHOP + 3));
170173
err = nlmsg_perm(nlmsg_type, perm, nlmsg_route_perms,
171174
sizeof(nlmsg_route_perms));
172175
break;

0 commit comments

Comments
 (0)