Skip to content

Commit 712bdbb

Browse files
jtlaytonchucklever
authored andcommitted
sunrpc: add netlink upcall for the auth.unix.ip cache
Add netlink-based cache upcall support for the ip_map (auth.unix.ip) cache, using the sunrpc generic netlink family. Add ip-map attribute-set (seqno, class, addr, domain, negative, expiry), ip-map-reqs wrapper, and ip-map-get-reqs / ip-map-set-reqs operations to the sunrpc_cache YAML spec and generated headers. Implement sunrpc_nl_ip_map_get_reqs_dumpit() which snapshots pending ip_map cache requests and sends each entry's seqno, class name, and IP address over netlink. Implement sunrpc_nl_ip_map_set_reqs_doit() which parses ip_map cache responses from userspace (class, addr, expiry, and domain name or negative flag) and updates the cache via __ip_map_lookup() / __ip_map_update(). Wire up ip_map_notify() callback in ip_map_cache_template so cache misses trigger SUNRPC_CMD_CACHE_NOTIFY multicast events with SUNRPC_CACHE_TYPE_IP_MAP. Signed-off-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent af81cb2 commit 712bdbb

5 files changed

Lines changed: 356 additions & 0 deletions

File tree

Documentation/netlink/specs/sunrpc_cache.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,35 @@ attribute-sets:
2020
name: cache-type
2121
type: u32
2222
enum: cache-type
23+
-
24+
name: ip-map
25+
attributes:
26+
-
27+
name: seqno
28+
type: u64
29+
-
30+
name: class
31+
type: string
32+
-
33+
name: addr
34+
type: string
35+
-
36+
name: domain
37+
type: string
38+
-
39+
name: negative
40+
type: flag
41+
-
42+
name: expiry
43+
type: u64
44+
-
45+
name: ip-map-reqs
46+
attributes:
47+
-
48+
name: requests
49+
type: nest
50+
nested-attributes: ip-map
51+
multi-attr: true
2352

2453
operations:
2554
list:
@@ -31,6 +60,24 @@ operations:
3160
event:
3261
attributes:
3362
- cache-type
63+
-
64+
name: ip-map-get-reqs
65+
doc: Dump all pending ip_map requests
66+
attribute-set: ip-map-reqs
67+
flags: [admin-perm]
68+
dump:
69+
request:
70+
attributes:
71+
- requests
72+
-
73+
name: ip-map-set-reqs
74+
doc: Respond to one or more ip_map requests
75+
attribute-set: ip-map-reqs
76+
flags: [admin-perm]
77+
do:
78+
request:
79+
attributes:
80+
- requests
3481

3582
mcast-groups:
3683
list:

include/uapi/linux/sunrpc_netlink.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,29 @@ enum {
2222
SUNRPC_A_CACHE_NOTIFY_MAX = (__SUNRPC_A_CACHE_NOTIFY_MAX - 1)
2323
};
2424

25+
enum {
26+
SUNRPC_A_IP_MAP_SEQNO = 1,
27+
SUNRPC_A_IP_MAP_CLASS,
28+
SUNRPC_A_IP_MAP_ADDR,
29+
SUNRPC_A_IP_MAP_DOMAIN,
30+
SUNRPC_A_IP_MAP_NEGATIVE,
31+
SUNRPC_A_IP_MAP_EXPIRY,
32+
33+
__SUNRPC_A_IP_MAP_MAX,
34+
SUNRPC_A_IP_MAP_MAX = (__SUNRPC_A_IP_MAP_MAX - 1)
35+
};
36+
37+
enum {
38+
SUNRPC_A_IP_MAP_REQS_REQUESTS = 1,
39+
40+
__SUNRPC_A_IP_MAP_REQS_MAX,
41+
SUNRPC_A_IP_MAP_REQS_MAX = (__SUNRPC_A_IP_MAP_REQS_MAX - 1)
42+
};
43+
2544
enum {
2645
SUNRPC_CMD_CACHE_NOTIFY = 1,
46+
SUNRPC_CMD_IP_MAP_GET_REQS,
47+
SUNRPC_CMD_IP_MAP_SET_REQS,
2748

2849
__SUNRPC_CMD_MAX,
2950
SUNRPC_CMD_MAX = (__SUNRPC_CMD_MAX - 1)

net/sunrpc/netlink.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,42 @@
1212

1313
#include <uapi/linux/sunrpc_netlink.h>
1414

15+
/* Common nested types */
16+
const struct nla_policy sunrpc_ip_map_nl_policy[SUNRPC_A_IP_MAP_EXPIRY + 1] = {
17+
[SUNRPC_A_IP_MAP_SEQNO] = { .type = NLA_U64, },
18+
[SUNRPC_A_IP_MAP_CLASS] = { .type = NLA_NUL_STRING, },
19+
[SUNRPC_A_IP_MAP_ADDR] = { .type = NLA_NUL_STRING, },
20+
[SUNRPC_A_IP_MAP_DOMAIN] = { .type = NLA_NUL_STRING, },
21+
[SUNRPC_A_IP_MAP_NEGATIVE] = { .type = NLA_FLAG, },
22+
[SUNRPC_A_IP_MAP_EXPIRY] = { .type = NLA_U64, },
23+
};
24+
25+
/* SUNRPC_CMD_IP_MAP_GET_REQS - dump */
26+
static const struct nla_policy sunrpc_ip_map_get_reqs_nl_policy[SUNRPC_A_IP_MAP_REQS_REQUESTS + 1] = {
27+
[SUNRPC_A_IP_MAP_REQS_REQUESTS] = NLA_POLICY_NESTED(sunrpc_ip_map_nl_policy),
28+
};
29+
30+
/* SUNRPC_CMD_IP_MAP_SET_REQS - do */
31+
static const struct nla_policy sunrpc_ip_map_set_reqs_nl_policy[SUNRPC_A_IP_MAP_REQS_REQUESTS + 1] = {
32+
[SUNRPC_A_IP_MAP_REQS_REQUESTS] = NLA_POLICY_NESTED(sunrpc_ip_map_nl_policy),
33+
};
34+
1535
/* Ops table for sunrpc */
1636
static const struct genl_split_ops sunrpc_nl_ops[] = {
37+
{
38+
.cmd = SUNRPC_CMD_IP_MAP_GET_REQS,
39+
.dumpit = sunrpc_nl_ip_map_get_reqs_dumpit,
40+
.policy = sunrpc_ip_map_get_reqs_nl_policy,
41+
.maxattr = SUNRPC_A_IP_MAP_REQS_REQUESTS,
42+
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DUMP,
43+
},
44+
{
45+
.cmd = SUNRPC_CMD_IP_MAP_SET_REQS,
46+
.doit = sunrpc_nl_ip_map_set_reqs_doit,
47+
.policy = sunrpc_ip_map_set_reqs_nl_policy,
48+
.maxattr = SUNRPC_A_IP_MAP_REQS_REQUESTS,
49+
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO,
50+
},
1751
};
1852

1953
static const struct genl_multicast_group sunrpc_nl_mcgrps[] = {

net/sunrpc/netlink.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212

1313
#include <uapi/linux/sunrpc_netlink.h>
1414

15+
/* Common nested types */
16+
extern const struct nla_policy sunrpc_ip_map_nl_policy[SUNRPC_A_IP_MAP_EXPIRY + 1];
17+
18+
int sunrpc_nl_ip_map_get_reqs_dumpit(struct sk_buff *skb,
19+
struct netlink_callback *cb);
20+
int sunrpc_nl_ip_map_set_reqs_doit(struct sk_buff *skb,
21+
struct genl_info *info);
22+
1523
enum {
1624
SUNRPC_NLGRP_NONE,
1725
SUNRPC_NLGRP_EXPORTD,

0 commit comments

Comments
 (0)