diff options
Diffstat (limited to 'net/tipc/netlink.c')
| -rw-r--r-- | net/tipc/netlink.c | 64 |
1 files changed, 5 insertions, 59 deletions
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c index b891e3905bc4..7f6475efc984 100644 --- a/net/tipc/netlink.c +++ b/net/tipc/netlink.c | |||
| @@ -35,7 +35,6 @@ | |||
| 35 | */ | 35 | */ |
| 36 | 36 | ||
| 37 | #include "core.h" | 37 | #include "core.h" |
| 38 | #include "config.h" | ||
| 39 | #include "socket.h" | 38 | #include "socket.h" |
| 40 | #include "name_table.h" | 39 | #include "name_table.h" |
| 41 | #include "bearer.h" | 40 | #include "bearer.h" |
| @@ -44,36 +43,6 @@ | |||
| 44 | #include "net.h" | 43 | #include "net.h" |
| 45 | #include <net/genetlink.h> | 44 | #include <net/genetlink.h> |
| 46 | 45 | ||
| 47 | static int handle_cmd(struct sk_buff *skb, struct genl_info *info) | ||
| 48 | { | ||
| 49 | struct sk_buff *rep_buf; | ||
| 50 | struct nlmsghdr *rep_nlh; | ||
| 51 | struct nlmsghdr *req_nlh = info->nlhdr; | ||
| 52 | struct tipc_genlmsghdr *req_userhdr = info->userhdr; | ||
| 53 | int hdr_space = nlmsg_total_size(GENL_HDRLEN + TIPC_GENL_HDRLEN); | ||
| 54 | u16 cmd; | ||
| 55 | |||
| 56 | if ((req_userhdr->cmd & 0xC000) && (!netlink_capable(skb, CAP_NET_ADMIN))) | ||
| 57 | cmd = TIPC_CMD_NOT_NET_ADMIN; | ||
| 58 | else | ||
| 59 | cmd = req_userhdr->cmd; | ||
| 60 | |||
| 61 | rep_buf = tipc_cfg_do_cmd(req_userhdr->dest, cmd, | ||
| 62 | nlmsg_data(req_nlh) + GENL_HDRLEN + TIPC_GENL_HDRLEN, | ||
| 63 | nlmsg_attrlen(req_nlh, GENL_HDRLEN + TIPC_GENL_HDRLEN), | ||
| 64 | hdr_space); | ||
| 65 | |||
| 66 | if (rep_buf) { | ||
| 67 | skb_push(rep_buf, hdr_space); | ||
| 68 | rep_nlh = nlmsg_hdr(rep_buf); | ||
| 69 | memcpy(rep_nlh, req_nlh, hdr_space); | ||
| 70 | rep_nlh->nlmsg_len = rep_buf->len; | ||
| 71 | genlmsg_unicast(&init_net, rep_buf, NETLINK_CB(skb).portid); | ||
| 72 | } | ||
| 73 | |||
| 74 | return 0; | ||
| 75 | } | ||
| 76 | |||
| 77 | static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = { | 46 | static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = { |
| 78 | [TIPC_NLA_UNSPEC] = { .type = NLA_UNSPEC, }, | 47 | [TIPC_NLA_UNSPEC] = { .type = NLA_UNSPEC, }, |
| 79 | [TIPC_NLA_BEARER] = { .type = NLA_NESTED, }, | 48 | [TIPC_NLA_BEARER] = { .type = NLA_NESTED, }, |
| @@ -86,32 +55,16 @@ static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = { | |||
| 86 | [TIPC_NLA_NAME_TABLE] = { .type = NLA_NESTED, } | 55 | [TIPC_NLA_NAME_TABLE] = { .type = NLA_NESTED, } |
| 87 | }; | 56 | }; |
| 88 | 57 | ||
| 89 | /* Legacy ASCII API */ | ||
| 90 | static struct genl_family tipc_genl_family = { | ||
| 91 | .id = GENL_ID_GENERATE, | ||
| 92 | .name = TIPC_GENL_NAME, | ||
| 93 | .version = TIPC_GENL_VERSION, | ||
| 94 | .hdrsize = TIPC_GENL_HDRLEN, | ||
| 95 | .maxattr = 0, | ||
| 96 | }; | ||
| 97 | |||
| 98 | /* Legacy ASCII API */ | ||
| 99 | static struct genl_ops tipc_genl_ops[] = { | ||
| 100 | { | ||
| 101 | .cmd = TIPC_GENL_CMD, | ||
| 102 | .doit = handle_cmd, | ||
| 103 | }, | ||
| 104 | }; | ||
| 105 | |||
| 106 | /* Users of the legacy API (tipc-config) can't handle that we add operations, | 58 | /* Users of the legacy API (tipc-config) can't handle that we add operations, |
| 107 | * so we have a separate genl handling for the new API. | 59 | * so we have a separate genl handling for the new API. |
| 108 | */ | 60 | */ |
| 109 | struct genl_family tipc_genl_v2_family = { | 61 | struct genl_family tipc_genl_family = { |
| 110 | .id = GENL_ID_GENERATE, | 62 | .id = GENL_ID_GENERATE, |
| 111 | .name = TIPC_GENL_V2_NAME, | 63 | .name = TIPC_GENL_V2_NAME, |
| 112 | .version = TIPC_GENL_V2_VERSION, | 64 | .version = TIPC_GENL_V2_VERSION, |
| 113 | .hdrsize = 0, | 65 | .hdrsize = 0, |
| 114 | .maxattr = TIPC_NLA_MAX, | 66 | .maxattr = TIPC_NLA_MAX, |
| 67 | .netnsok = true, | ||
| 115 | }; | 68 | }; |
| 116 | 69 | ||
| 117 | static const struct genl_ops tipc_genl_v2_ops[] = { | 70 | static const struct genl_ops tipc_genl_v2_ops[] = { |
| @@ -197,9 +150,9 @@ static const struct genl_ops tipc_genl_v2_ops[] = { | |||
| 197 | 150 | ||
| 198 | int tipc_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr ***attr) | 151 | int tipc_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr ***attr) |
| 199 | { | 152 | { |
| 200 | u32 maxattr = tipc_genl_v2_family.maxattr; | 153 | u32 maxattr = tipc_genl_family.maxattr; |
| 201 | 154 | ||
| 202 | *attr = tipc_genl_v2_family.attrbuf; | 155 | *attr = tipc_genl_family.attrbuf; |
| 203 | if (!*attr) | 156 | if (!*attr) |
| 204 | return -EOPNOTSUPP; | 157 | return -EOPNOTSUPP; |
| 205 | 158 | ||
| @@ -210,13 +163,7 @@ int tipc_netlink_start(void) | |||
| 210 | { | 163 | { |
| 211 | int res; | 164 | int res; |
| 212 | 165 | ||
| 213 | res = genl_register_family_with_ops(&tipc_genl_family, tipc_genl_ops); | 166 | res = genl_register_family_with_ops(&tipc_genl_family, |
| 214 | if (res) { | ||
| 215 | pr_err("Failed to register legacy interface\n"); | ||
| 216 | return res; | ||
| 217 | } | ||
| 218 | |||
| 219 | res = genl_register_family_with_ops(&tipc_genl_v2_family, | ||
| 220 | tipc_genl_v2_ops); | 167 | tipc_genl_v2_ops); |
| 221 | if (res) { | 168 | if (res) { |
| 222 | pr_err("Failed to register netlink interface\n"); | 169 | pr_err("Failed to register netlink interface\n"); |
| @@ -228,5 +175,4 @@ int tipc_netlink_start(void) | |||
| 228 | void tipc_netlink_stop(void) | 175 | void tipc_netlink_stop(void) |
| 229 | { | 176 | { |
| 230 | genl_unregister_family(&tipc_genl_family); | 177 | genl_unregister_family(&tipc_genl_family); |
| 231 | genl_unregister_family(&tipc_genl_v2_family); | ||
| 232 | } | 178 | } |
