3535 */
3636
3737#include "core.h"
38- #include "config.h"
3938#include "socket.h"
4039#include "name_table.h"
4140#include "bearer.h"
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-
8046static 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
203151int 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)
233175void tipc_netlink_stop (void )
234176{
235177 genl_unregister_family (& tipc_genl_family );
236- genl_unregister_family (& tipc_genl_v2_family );
237178}
0 commit comments