Skip to content

Commit bfb3e5d

Browse files
Richard Alpedavem330
authored andcommitted
tipc: move and rename the legacy nl api to "nl compat"
The new netlink API is no longer "v2" but rather the standard API and the legacy API is now "nl compat". We split them into separate start/stop and put them in different files in order to further distinguish them. Signed-off-by: Richard Alpe <richard.alpe@ericsson.com> Reviewed-by: Erik Hugne <erik.hugne@ericsson.com> Reviewed-by: Ying Xue <ying.xue@windriver.com> Reviewed-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent c8ac18f commit bfb3e5d

File tree

13 files changed

+130
-76
lines changed

13 files changed

+130
-76
lines changed

net/tipc/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ obj-$(CONFIG_TIPC) := tipc.o
77
tipc-y += addr.o bcast.o bearer.o config.o \
88
core.o link.o discover.o msg.o \
99
name_distr.o subscr.o name_table.o net.o \
10-
netlink.o node.o socket.o log.o eth_media.o \
11-
server.o
10+
netlink.o netlink_compat.o node.o socket.o log.o eth_media.o \
11+
server.o socket.o
1212

1313
tipc-$(CONFIG_TIPC_MEDIA_IB) += ib_media.o
1414
tipc-$(CONFIG_SYSCTL) += sysctl.o

net/tipc/bcast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ int tipc_nl_add_bc_link(struct net *net, struct tipc_nl_msg *msg)
810810

811811
tipc_bclink_lock(net);
812812

813-
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family,
813+
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
814814
NLM_F_MULTI, TIPC_NL_LINK_GET);
815815
if (!hdr)
816816
return -EMSGSIZE;

net/tipc/bearer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ static int __tipc_nl_add_bearer(struct tipc_nl_msg *msg,
658658
struct nlattr *attrs;
659659
struct nlattr *prop;
660660

661-
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family,
661+
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
662662
NLM_F_MULTI, TIPC_NL_BEARER_GET);
663663
if (!hdr)
664664
return -EMSGSIZE;
@@ -924,7 +924,7 @@ static int __tipc_nl_add_media(struct tipc_nl_msg *msg,
924924
struct nlattr *attrs;
925925
struct nlattr *prop;
926926

927-
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family,
927+
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
928928
NLM_F_MULTI, TIPC_NL_MEDIA_GET);
929929
if (!hdr)
930930
return -EMSGSIZE;

net/tipc/core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ static int __init tipc_init(void)
111111
if (err)
112112
goto out_netlink;
113113

114+
err = tipc_netlink_compat_start();
115+
if (err)
116+
goto out_netlink_compat;
117+
114118
err = tipc_socket_init();
115119
if (err)
116120
goto out_socket;
@@ -136,6 +140,8 @@ static int __init tipc_init(void)
136140
out_sysctl:
137141
tipc_socket_stop();
138142
out_socket:
143+
tipc_netlink_compat_stop();
144+
out_netlink_compat:
139145
tipc_netlink_stop();
140146
out_netlink:
141147
pr_err("Unable to start in single node mode\n");
@@ -146,6 +152,7 @@ static void __exit tipc_exit(void)
146152
{
147153
tipc_bearer_cleanup();
148154
tipc_netlink_stop();
155+
tipc_netlink_compat_stop();
149156
tipc_socket_stop();
150157
tipc_unregister_sysctl();
151158
unregister_pernet_subsys(&tipc_net_ops);

net/tipc/core.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,4 @@ void tipc_unregister_sysctl(void);
115115
#define tipc_register_sysctl() 0
116116
#define tipc_unregister_sysctl()
117117
#endif
118-
119118
#endif

net/tipc/link.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2498,7 +2498,7 @@ static int __tipc_nl_add_link(struct net *net, struct tipc_nl_msg *msg,
24982498
struct nlattr *prop;
24992499
struct tipc_net *tn = net_generic(net, tipc_net_id);
25002500

2501-
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family,
2501+
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
25022502
NLM_F_MULTI, TIPC_NL_LINK_GET);
25032503
if (!hdr)
25042504
return -EMSGSIZE;

net/tipc/name_table.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,7 +1055,7 @@ static int __tipc_nl_add_nametable_publ(struct tipc_nl_msg *msg,
10551055
*last_publ = p->key;
10561056

10571057
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq,
1058-
&tipc_genl_v2_family, NLM_F_MULTI,
1058+
&tipc_genl_family, NLM_F_MULTI,
10591059
TIPC_NL_NAME_TABLE_GET);
10601060
if (!hdr)
10611061
return -EMSGSIZE;

net/tipc/net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static int __tipc_nl_add_net(struct net *net, struct tipc_nl_msg *msg)
156156
void *hdr;
157157
struct nlattr *attrs;
158158

159-
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family,
159+
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
160160
NLM_F_MULTI, TIPC_NL_NET_GET);
161161
if (!hdr)
162162
return -EMSGSIZE;

net/tipc/netlink.c

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
*/
3636

3737
#include "core.h"
38-
#include "config.h"
3938
#include "socket.h"
4039
#include "name_table.h"
4140
#include "bearer.h"
@@ -44,39 +43,6 @@
4443
#include "net.h"
4544
#include <net/genetlink.h>
4645

47-
static int handle_cmd(struct sk_buff *skb, struct genl_info *info)
48-
{
49-
struct net *net = genl_info_net(info);
50-
struct sk_buff *rep_buf;
51-
struct nlmsghdr *rep_nlh;
52-
struct nlmsghdr *req_nlh = info->nlhdr;
53-
struct tipc_genlmsghdr *req_userhdr = info->userhdr;
54-
int hdr_space = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN);
55-
u16 cmd;
56-
57-
if ((req_userhdr->cmd & 0xC000) &&
58-
(!netlink_net_capable(skb, CAP_NET_ADMIN)))
59-
cmd = TIPC_CMD_NOT_NET_ADMIN;
60-
else
61-
cmd = req_userhdr->cmd;
62-
63-
rep_buf = tipc_cfg_do_cmd(net, req_userhdr->dest, cmd,
64-
nlmsg_data(req_nlh) + GENL_HDRLEN +
65-
TIPC_GENL_HDRLEN,
66-
nlmsg_attrlen(req_nlh, GENL_HDRLEN +
67-
TIPC_GENL_HDRLEN), hdr_space);
68-
69-
if (rep_buf) {
70-
skb_push(rep_buf, hdr_space);
71-
rep_nlh = nlmsg_hdr(rep_buf);
72-
memcpy(rep_nlh, req_nlh, hdr_space);
73-
rep_nlh->nlmsg_len = rep_buf->len;
74-
genlmsg_unicast(net, rep_buf, NETLINK_CB(skb).portid);
75-
}
76-
77-
return 0;
78-
}
79-
8046
static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = {
8147
[TIPC_NLA_UNSPEC] = { .type = NLA_UNSPEC, },
8248
[TIPC_NLA_BEARER] = { .type = NLA_NESTED, },
@@ -89,28 +55,10 @@ static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = {
8955
[TIPC_NLA_NAME_TABLE] = { .type = NLA_NESTED, }
9056
};
9157

92-
/* Legacy ASCII API */
93-
static struct genl_family tipc_genl_family = {
94-
.id = GENL_ID_GENERATE,
95-
.name = TIPC_GENL_NAME,
96-
.version = TIPC_GENL_VERSION,
97-
.hdrsize = TIPC_GENL_HDRLEN,
98-
.maxattr = 0,
99-
.netnsok = true,
100-
};
101-
102-
/* Legacy ASCII API */
103-
static struct genl_ops tipc_genl_ops[] = {
104-
{
105-
.cmd = TIPC_GENL_CMD,
106-
.doit = handle_cmd,
107-
},
108-
};
109-
11058
/* Users of the legacy API (tipc-config) can't handle that we add operations,
11159
* so we have a separate genl handling for the new API.
11260
*/
113-
struct genl_family tipc_genl_v2_family = {
61+
struct genl_family tipc_genl_family = {
11462
.id = GENL_ID_GENERATE,
11563
.name = TIPC_GENL_V2_NAME,
11664
.version = TIPC_GENL_V2_VERSION,
@@ -202,9 +150,9 @@ static const struct genl_ops tipc_genl_v2_ops[] = {
202150

203151
int tipc_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr ***attr)
204152
{
205-
u32 maxattr = tipc_genl_v2_family.maxattr;
153+
u32 maxattr = tipc_genl_family.maxattr;
206154

207-
*attr = tipc_genl_v2_family.attrbuf;
155+
*attr = tipc_genl_family.attrbuf;
208156
if (!*attr)
209157
return -EOPNOTSUPP;
210158

@@ -215,13 +163,7 @@ int tipc_netlink_start(void)
215163
{
216164
int res;
217165

218-
res = genl_register_family_with_ops(&tipc_genl_family, tipc_genl_ops);
219-
if (res) {
220-
pr_err("Failed to register legacy interface\n");
221-
return res;
222-
}
223-
224-
res = genl_register_family_with_ops(&tipc_genl_v2_family,
166+
res = genl_register_family_with_ops(&tipc_genl_family,
225167
tipc_genl_v2_ops);
226168
if (res) {
227169
pr_err("Failed to register netlink interface\n");
@@ -233,5 +175,4 @@ int tipc_netlink_start(void)
233175
void tipc_netlink_stop(void)
234176
{
235177
genl_unregister_family(&tipc_genl_family);
236-
genl_unregister_family(&tipc_genl_v2_family);
237178
}

net/tipc/netlink.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#ifndef _TIPC_NETLINK_H
3737
#define _TIPC_NETLINK_H
3838

39-
extern struct genl_family tipc_genl_v2_family;
39+
extern struct genl_family tipc_genl_family;
4040
int tipc_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr ***buf);
4141

4242
struct tipc_nl_msg {
@@ -46,6 +46,8 @@ struct tipc_nl_msg {
4646
};
4747

4848
int tipc_netlink_start(void);
49+
int tipc_netlink_compat_start(void);
4950
void tipc_netlink_stop(void);
51+
void tipc_netlink_compat_stop(void);
5052

5153
#endif

0 commit comments

Comments
 (0)