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

net/tipc/netlink_compat.c

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2014, Ericsson AB
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright
9+
* notice, this list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright
11+
* notice, this list of conditions and the following disclaimer in the
12+
* documentation and/or other materials provided with the distribution.
13+
* 3. Neither the names of the copyright holders nor the names of its
14+
* contributors may be used to endorse or promote products derived from
15+
* this software without specific prior written permission.
16+
*
17+
* Alternatively, this software may be distributed under the terms of the
18+
* GNU General Public License ("GPL") version 2 as published by the Free
19+
* Software Foundation.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
* POSSIBILITY OF SUCH DAMAGE.
32+
*/
33+
34+
#include "core.h"
35+
#include "config.h"
36+
#include <net/genetlink.h>
37+
#include <linux/tipc_config.h>
38+
39+
static int handle_cmd(struct sk_buff *skb, struct genl_info *info)
40+
{
41+
struct net *net = genl_info_net(info);
42+
struct sk_buff *rep_buf;
43+
struct nlmsghdr *rep_nlh;
44+
struct nlmsghdr *req_nlh = info->nlhdr;
45+
struct tipc_genlmsghdr *req_userhdr = info->userhdr;
46+
int hdr_space = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN);
47+
u16 cmd;
48+
49+
if ((req_userhdr->cmd & 0xC000) &&
50+
(!netlink_net_capable(skb, CAP_NET_ADMIN)))
51+
cmd = TIPC_CMD_NOT_NET_ADMIN;
52+
else
53+
cmd = req_userhdr->cmd;
54+
55+
rep_buf = tipc_cfg_do_cmd(net, req_userhdr->dest, cmd,
56+
nlmsg_data(req_nlh) + GENL_HDRLEN +
57+
TIPC_GENL_HDRLEN,
58+
nlmsg_attrlen(req_nlh, GENL_HDRLEN +
59+
TIPC_GENL_HDRLEN), hdr_space);
60+
61+
if (rep_buf) {
62+
skb_push(rep_buf, hdr_space);
63+
rep_nlh = nlmsg_hdr(rep_buf);
64+
memcpy(rep_nlh, req_nlh, hdr_space);
65+
rep_nlh->nlmsg_len = rep_buf->len;
66+
genlmsg_unicast(net, rep_buf, NETLINK_CB(skb).portid);
67+
}
68+
69+
return 0;
70+
}
71+
72+
static struct genl_family tipc_genl_compat_family = {
73+
.id = GENL_ID_GENERATE,
74+
.name = TIPC_GENL_NAME,
75+
.version = TIPC_GENL_VERSION,
76+
.hdrsize = TIPC_GENL_HDRLEN,
77+
.maxattr = 0,
78+
.netnsok = true,
79+
};
80+
81+
static struct genl_ops tipc_genl_compat_ops[] = {
82+
{
83+
.cmd = TIPC_GENL_CMD,
84+
.doit = handle_cmd,
85+
},
86+
};
87+
88+
int tipc_netlink_compat_start(void)
89+
{
90+
int res;
91+
92+
res = genl_register_family_with_ops(&tipc_genl_compat_family,
93+
tipc_genl_compat_ops);
94+
if (res) {
95+
pr_err("Failed to register legacy compat interface\n");
96+
return res;
97+
}
98+
99+
return 0;
100+
}
101+
102+
void tipc_netlink_compat_stop(void)
103+
{
104+
genl_unregister_family(&tipc_genl_compat_family);
105+
}

net/tipc/node.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ static int __tipc_nl_add_node(struct tipc_nl_msg *msg, struct tipc_node *node)
623623
void *hdr;
624624
struct nlattr *attrs;
625625

626-
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_v2_family,
626+
hdr = genlmsg_put(msg->skb, msg->portid, msg->seq, &tipc_genl_family,
627627
NLM_F_MULTI, TIPC_NL_NODE_GET);
628628
if (!hdr)
629629
return -EMSGSIZE;

net/tipc/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2783,7 +2783,7 @@ static int __tipc_nl_add_sk(struct sk_buff *skb, struct netlink_callback *cb,
27832783
struct tipc_net *tn = net_generic(net, tipc_net_id);
27842784

27852785
hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
2786-
&tipc_genl_v2_family, NLM_F_MULTI, TIPC_NL_SOCK_GET);
2786+
&tipc_genl_family, NLM_F_MULTI, TIPC_NL_SOCK_GET);
27872787
if (!hdr)
27882788
goto msg_cancel;
27892789

@@ -2864,7 +2864,7 @@ static int __tipc_nl_add_sk_publ(struct sk_buff *skb,
28642864
struct nlattr *attrs;
28652865

28662866
hdr = genlmsg_put(skb, NETLINK_CB(cb->skb).portid, cb->nlh->nlmsg_seq,
2867-
&tipc_genl_v2_family, NLM_F_MULTI, TIPC_NL_PUBL_GET);
2867+
&tipc_genl_family, NLM_F_MULTI, TIPC_NL_PUBL_GET);
28682868
if (!hdr)
28692869
goto msg_cancel;
28702870

0 commit comments

Comments
 (0)