Skip to content

Commit 1d562c3

Browse files
kuba-mooPaolo Abeni
authored andcommitted
net: fou: use policy and operation tables generated from the spec
Generate and plug in the spec-based tables. A little bit of renaming is needed in the FOU code. Acked-by: Stanislav Fomichev <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 08d3232 commit 1d562c3

File tree

4 files changed

+81
-41
lines changed

4 files changed

+81
-41
lines changed

net/ipv4/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ obj-$(CONFIG_IP_MROUTE) += ipmr.o
2626
obj-$(CONFIG_IP_MROUTE_COMMON) += ipmr_base.o
2727
obj-$(CONFIG_NET_IPIP) += ipip.o
2828
gre-y := gre_demux.o
29-
fou-y := fou_core.o
29+
fou-y := fou_core.o fou_nl.o
3030
obj-$(CONFIG_NET_FOU) += fou.o
3131
obj-$(CONFIG_NET_IPGRE_DEMUX) += gre.o
3232
obj-$(CONFIG_NET_IPGRE) += ip_gre.o

net/ipv4/fou_core.c

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <uapi/linux/fou.h>
2020
#include <uapi/linux/genetlink.h>
2121

22+
#include "fou_nl.h"
23+
2224
struct fou {
2325
struct socket *sock;
2426
u8 protocol;
@@ -640,20 +642,6 @@ static int fou_destroy(struct net *net, struct fou_cfg *cfg)
640642

641643
static struct genl_family fou_nl_family;
642644

643-
static const struct nla_policy fou_nl_policy[FOU_ATTR_MAX + 1] = {
644-
[FOU_ATTR_PORT] = { .type = NLA_U16, },
645-
[FOU_ATTR_AF] = { .type = NLA_U8, },
646-
[FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
647-
[FOU_ATTR_TYPE] = { .type = NLA_U8, },
648-
[FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
649-
[FOU_ATTR_LOCAL_V4] = { .type = NLA_U32, },
650-
[FOU_ATTR_PEER_V4] = { .type = NLA_U32, },
651-
[FOU_ATTR_LOCAL_V6] = { .len = sizeof(struct in6_addr), },
652-
[FOU_ATTR_PEER_V6] = { .len = sizeof(struct in6_addr), },
653-
[FOU_ATTR_PEER_PORT] = { .type = NLA_U16, },
654-
[FOU_ATTR_IFINDEX] = { .type = NLA_S32, },
655-
};
656-
657645
static int parse_nl_config(struct genl_info *info,
658646
struct fou_cfg *cfg)
659647
{
@@ -745,7 +733,7 @@ static int parse_nl_config(struct genl_info *info,
745733
return 0;
746734
}
747735

748-
static int fou_nl_cmd_add_port(struct sk_buff *skb, struct genl_info *info)
736+
int fou_nl_add_doit(struct sk_buff *skb, struct genl_info *info)
749737
{
750738
struct net *net = genl_info_net(info);
751739
struct fou_cfg cfg;
@@ -758,7 +746,7 @@ static int fou_nl_cmd_add_port(struct sk_buff *skb, struct genl_info *info)
758746
return fou_create(net, &cfg, NULL);
759747
}
760748

761-
static int fou_nl_cmd_rm_port(struct sk_buff *skb, struct genl_info *info)
749+
int fou_nl_del_doit(struct sk_buff *skb, struct genl_info *info)
762750
{
763751
struct net *net = genl_info_net(info);
764752
struct fou_cfg cfg;
@@ -827,7 +815,7 @@ static int fou_dump_info(struct fou *fou, u32 portid, u32 seq,
827815
return -EMSGSIZE;
828816
}
829817

830-
static int fou_nl_cmd_get_port(struct sk_buff *skb, struct genl_info *info)
818+
int fou_nl_get_doit(struct sk_buff *skb, struct genl_info *info)
831819
{
832820
struct net *net = genl_info_net(info);
833821
struct fou_net *fn = net_generic(net, fou_net_id);
@@ -874,7 +862,7 @@ static int fou_nl_cmd_get_port(struct sk_buff *skb, struct genl_info *info)
874862
return ret;
875863
}
876864

877-
static int fou_nl_dump(struct sk_buff *skb, struct netlink_callback *cb)
865+
int fou_nl_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb)
878866
{
879867
struct net *net = sock_net(skb->sk);
880868
struct fou_net *fn = net_generic(net, fou_net_id);
@@ -897,33 +885,12 @@ static int fou_nl_dump(struct sk_buff *skb, struct netlink_callback *cb)
897885
return skb->len;
898886
}
899887

900-
static const struct genl_small_ops fou_nl_ops[] = {
901-
{
902-
.cmd = FOU_CMD_ADD,
903-
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
904-
.doit = fou_nl_cmd_add_port,
905-
.flags = GENL_ADMIN_PERM,
906-
},
907-
{
908-
.cmd = FOU_CMD_DEL,
909-
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
910-
.doit = fou_nl_cmd_rm_port,
911-
.flags = GENL_ADMIN_PERM,
912-
},
913-
{
914-
.cmd = FOU_CMD_GET,
915-
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
916-
.doit = fou_nl_cmd_get_port,
917-
.dumpit = fou_nl_dump,
918-
},
919-
};
920-
921888
static struct genl_family fou_nl_family __ro_after_init = {
922889
.hdrsize = 0,
923890
.name = FOU_GENL_NAME,
924891
.version = FOU_GENL_VERSION,
925892
.maxattr = FOU_ATTR_MAX,
926-
.policy = fou_nl_policy,
893+
.policy = fou_nl_policy,
927894
.netnsok = true,
928895
.module = THIS_MODULE,
929896
.small_ops = fou_nl_ops,

net/ipv4/fou_nl.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: BSD-3-Clause
2+
/* Do not edit directly, auto-generated from: */
3+
/* Documentation/netlink/specs/fou.yaml */
4+
/* YNL-GEN kernel source */
5+
6+
#include <net/netlink.h>
7+
#include <net/genetlink.h>
8+
9+
#include "fou_nl.h"
10+
11+
#include <linux/fou.h>
12+
13+
/* Global operation policy for fou */
14+
const struct nla_policy fou_nl_policy[FOU_ATTR_IFINDEX + 1] = {
15+
[FOU_ATTR_PORT] = { .type = NLA_U16, },
16+
[FOU_ATTR_AF] = { .type = NLA_U8, },
17+
[FOU_ATTR_IPPROTO] = { .type = NLA_U8, },
18+
[FOU_ATTR_TYPE] = { .type = NLA_U8, },
19+
[FOU_ATTR_REMCSUM_NOPARTIAL] = { .type = NLA_FLAG, },
20+
[FOU_ATTR_LOCAL_V4] = { .type = NLA_U32, },
21+
[FOU_ATTR_LOCAL_V6] = { .len = 16, },
22+
[FOU_ATTR_PEER_V4] = { .type = NLA_U32, },
23+
[FOU_ATTR_PEER_V6] = { .len = 16, },
24+
[FOU_ATTR_PEER_PORT] = { .type = NLA_U16, },
25+
[FOU_ATTR_IFINDEX] = { .type = NLA_S32, },
26+
};
27+
28+
/* Ops table for fou */
29+
const struct genl_small_ops fou_nl_ops[3] = {
30+
{
31+
.cmd = FOU_CMD_ADD,
32+
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
33+
.doit = fou_nl_add_doit,
34+
.flags = GENL_ADMIN_PERM,
35+
},
36+
{
37+
.cmd = FOU_CMD_DEL,
38+
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
39+
.doit = fou_nl_del_doit,
40+
.flags = GENL_ADMIN_PERM,
41+
},
42+
{
43+
.cmd = FOU_CMD_GET,
44+
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
45+
.doit = fou_nl_get_doit,
46+
.dumpit = fou_nl_get_dumpit,
47+
},
48+
};

net/ipv4/fou_nl.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause */
2+
/* Do not edit directly, auto-generated from: */
3+
/* Documentation/netlink/specs/fou.yaml */
4+
/* YNL-GEN kernel header */
5+
6+
#ifndef _LINUX_FOU_GEN_H
7+
#define _LINUX_FOU_GEN_H
8+
9+
#include <net/netlink.h>
10+
#include <net/genetlink.h>
11+
12+
#include <linux/fou.h>
13+
14+
/* Global operation policy for fou */
15+
extern const struct nla_policy fou_nl_policy[FOU_ATTR_IFINDEX + 1];
16+
17+
/* Ops table for fou */
18+
extern const struct genl_small_ops fou_nl_ops[3];
19+
20+
int fou_nl_add_doit(struct sk_buff *skb, struct genl_info *info);
21+
int fou_nl_del_doit(struct sk_buff *skb, struct genl_info *info);
22+
int fou_nl_get_doit(struct sk_buff *skb, struct genl_info *info);
23+
int fou_nl_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
24+
25+
#endif /* _LINUX_FOU_GEN_H */

0 commit comments

Comments
 (0)