diff options
author | Richard Alpe <richard.alpe@ericsson.com> | 2014-11-20 04:29:07 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-11-21 15:01:29 -0500 |
commit | 0655f6a8635b1b66f2434d5556b1044c14b1ccaf (patch) | |
tree | 6c5080bcfb237f7718dee9dbc91a49b564556d43 | |
parent | 7cc76f51508219a74dca835745e4f84393820017 (diff) |
tipc: add bearer disable/enable to new netlink api
A new netlink API for tipc that can disable or enable a tipc bearer.
The new API is separated from the old API because of a bug in the
user space client (tipc-config). The problem is that older versions
of tipc-config has a very low receive limit and adding commands to
the legacy genl_opts struct causes the ctrl_getfamily() response
message to grow, subsequently breaking the tool.
The new API utilizes netlink policies for input validation. Where the
top-level netlink attributes are tipc-logical entities, like bearer.
The top level entities then contain nested attributes. In this case
a name, nested link properties and a domain.
Netlink commands implemented in this patch:
TIPC_NL_BEARER_ENABLE
TIPC_NL_BEARER_DISABLE
Netlink logical layout of bearer enable message:
-> bearer
-> name
[ -> domain ]
[
-> properties
-> priority
]
Netlink logical layout of bearer disable message:
-> bearer
-> name
Signed-off-by: Richard Alpe <richard.alpe@ericsson.com>
Reviewed-by: Erik Hugne <erik.hugne@ericsson.com>
Reviewed-by: Jon Maloy <jon.maloy@ericsson.com>
Acked-by: Ying Xue <ying.xue@windriver.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/uapi/linux/tipc_netlink.h | 83 | ||||
-rw-r--r-- | net/tipc/bearer.c | 99 | ||||
-rw-r--r-- | net/tipc/bearer.h | 7 | ||||
-rw-r--r-- | net/tipc/core.h | 1 | ||||
-rw-r--r-- | net/tipc/link.c | 47 | ||||
-rw-r--r-- | net/tipc/link.h | 3 | ||||
-rw-r--r-- | net/tipc/netlink.c | 42 | ||||
-rw-r--r-- | net/tipc/netlink.h | 41 |
8 files changed, 320 insertions, 3 deletions
diff --git a/include/uapi/linux/tipc_netlink.h b/include/uapi/linux/tipc_netlink.h new file mode 100644 index 000000000000..b9b710faa229 --- /dev/null +++ b/include/uapi/linux/tipc_netlink.h | |||
@@ -0,0 +1,83 @@ | |||
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 | #ifndef _LINUX_TIPC_NETLINK_H_ | ||
35 | #define _LINUX_TIPC_NETLINK_H_ | ||
36 | |||
37 | #define TIPC_GENL_V2_NAME "TIPCv2" | ||
38 | #define TIPC_GENL_V2_VERSION 0x1 | ||
39 | |||
40 | /* Netlink commands */ | ||
41 | enum { | ||
42 | TIPC_NL_UNSPEC, | ||
43 | TIPC_NL_LEGACY, | ||
44 | TIPC_NL_BEARER_DISABLE, | ||
45 | TIPC_NL_BEARER_ENABLE, | ||
46 | |||
47 | __TIPC_NL_CMD_MAX, | ||
48 | TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1 | ||
49 | }; | ||
50 | |||
51 | /* Top level netlink attributes */ | ||
52 | enum { | ||
53 | TIPC_NLA_UNSPEC, | ||
54 | TIPC_NLA_BEARER, /* nest */ | ||
55 | |||
56 | __TIPC_NLA_MAX, | ||
57 | TIPC_NLA_MAX = __TIPC_NLA_MAX - 1 | ||
58 | }; | ||
59 | |||
60 | /* Bearer info */ | ||
61 | enum { | ||
62 | TIPC_NLA_BEARER_UNSPEC, | ||
63 | TIPC_NLA_BEARER_NAME, /* string */ | ||
64 | TIPC_NLA_BEARER_PROP, /* nest */ | ||
65 | TIPC_NLA_BEARER_DOMAIN, /* u32 */ | ||
66 | |||
67 | __TIPC_NLA_BEARER_MAX, | ||
68 | TIPC_NLA_BEARER_MAX = __TIPC_NLA_BEARER_MAX - 1 | ||
69 | }; | ||
70 | |||
71 | /* Nest, link propreties. Valid for link, media and bearer */ | ||
72 | enum { | ||
73 | TIPC_NLA_PROP_UNSPEC, | ||
74 | |||
75 | TIPC_NLA_PROP_PRIO, /* u32 */ | ||
76 | TIPC_NLA_PROP_TOL, /* u32 */ | ||
77 | TIPC_NLA_PROP_WIN, /* u32 */ | ||
78 | |||
79 | __TIPC_NLA_PROP_MAX, | ||
80 | TIPC_NLA_PROP_MAX = __TIPC_NLA_PROP_MAX - 1 | ||
81 | }; | ||
82 | |||
83 | #endif | ||
diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index 264474394f9f..59815be0ab98 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/bearer.c: TIPC bearer code | 2 | * net/tipc/bearer.c: TIPC bearer code |
3 | * | 3 | * |
4 | * Copyright (c) 1996-2006, 2013, Ericsson AB | 4 | * Copyright (c) 1996-2006, 2013-2014, Ericsson AB |
5 | * Copyright (c) 2004-2006, 2010-2013, Wind River Systems | 5 | * Copyright (c) 2004-2006, 2010-2013, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -37,6 +37,7 @@ | |||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "config.h" | 38 | #include "config.h" |
39 | #include "bearer.h" | 39 | #include "bearer.h" |
40 | #include "link.h" | ||
40 | #include "discover.h" | 41 | #include "discover.h" |
41 | 42 | ||
42 | #define MAX_ADDR_STR 60 | 43 | #define MAX_ADDR_STR 60 |
@@ -49,6 +50,17 @@ static struct tipc_media * const media_info_array[] = { | |||
49 | NULL | 50 | NULL |
50 | }; | 51 | }; |
51 | 52 | ||
53 | static const struct nla_policy | ||
54 | tipc_nl_bearer_policy[TIPC_NLA_BEARER_MAX + 1] = { | ||
55 | [TIPC_NLA_BEARER_UNSPEC] = { .type = NLA_UNSPEC }, | ||
56 | [TIPC_NLA_BEARER_NAME] = { | ||
57 | .type = NLA_STRING, | ||
58 | .len = TIPC_MAX_BEARER_NAME | ||
59 | }, | ||
60 | [TIPC_NLA_BEARER_PROP] = { .type = NLA_NESTED }, | ||
61 | [TIPC_NLA_BEARER_DOMAIN] = { .type = NLA_U32 } | ||
62 | }; | ||
63 | |||
52 | struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1]; | 64 | struct tipc_bearer __rcu *bearer_list[MAX_BEARERS + 1]; |
53 | 65 | ||
54 | static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down); | 66 | static void bearer_disable(struct tipc_bearer *b_ptr, bool shutting_down); |
@@ -627,3 +639,88 @@ void tipc_bearer_stop(void) | |||
627 | } | 639 | } |
628 | } | 640 | } |
629 | } | 641 | } |
642 | |||
643 | int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info) | ||
644 | { | ||
645 | int err; | ||
646 | char *name; | ||
647 | struct tipc_bearer *bearer; | ||
648 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; | ||
649 | |||
650 | if (!info->attrs[TIPC_NLA_BEARER]) | ||
651 | return -EINVAL; | ||
652 | |||
653 | err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX, | ||
654 | info->attrs[TIPC_NLA_BEARER], | ||
655 | tipc_nl_bearer_policy); | ||
656 | if (err) | ||
657 | return err; | ||
658 | |||
659 | if (!attrs[TIPC_NLA_BEARER_NAME]) | ||
660 | return -EINVAL; | ||
661 | |||
662 | name = nla_data(attrs[TIPC_NLA_BEARER_NAME]); | ||
663 | |||
664 | rtnl_lock(); | ||
665 | bearer = tipc_bearer_find(name); | ||
666 | if (!bearer) { | ||
667 | rtnl_unlock(); | ||
668 | return -EINVAL; | ||
669 | } | ||
670 | |||
671 | bearer_disable(bearer, false); | ||
672 | rtnl_unlock(); | ||
673 | |||
674 | return 0; | ||
675 | } | ||
676 | |||
677 | int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) | ||
678 | { | ||
679 | int err; | ||
680 | char *bearer; | ||
681 | struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; | ||
682 | u32 domain; | ||
683 | u32 prio; | ||
684 | |||
685 | prio = TIPC_MEDIA_LINK_PRI; | ||
686 | domain = tipc_own_addr & TIPC_CLUSTER_MASK; | ||
687 | |||
688 | if (!info->attrs[TIPC_NLA_BEARER]) | ||
689 | return -EINVAL; | ||
690 | |||
691 | err = nla_parse_nested(attrs, TIPC_NLA_BEARER_MAX, | ||
692 | info->attrs[TIPC_NLA_BEARER], | ||
693 | tipc_nl_bearer_policy); | ||
694 | if (err) | ||
695 | return err; | ||
696 | |||
697 | if (!attrs[TIPC_NLA_BEARER_NAME]) | ||
698 | return -EINVAL; | ||
699 | |||
700 | bearer = nla_data(attrs[TIPC_NLA_BEARER_NAME]); | ||
701 | |||
702 | if (attrs[TIPC_NLA_BEARER_DOMAIN]) | ||
703 | domain = nla_get_u32(attrs[TIPC_NLA_BEARER_DOMAIN]); | ||
704 | |||
705 | if (attrs[TIPC_NLA_BEARER_PROP]) { | ||
706 | struct nlattr *props[TIPC_NLA_PROP_MAX + 1]; | ||
707 | |||
708 | err = tipc_nl_parse_link_prop(attrs[TIPC_NLA_BEARER_PROP], | ||
709 | props); | ||
710 | if (err) | ||
711 | return err; | ||
712 | |||
713 | if (props[TIPC_NLA_PROP_PRIO]) | ||
714 | prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]); | ||
715 | } | ||
716 | |||
717 | rtnl_lock(); | ||
718 | err = tipc_enable_bearer(bearer, domain, prio); | ||
719 | if (err) { | ||
720 | rtnl_unlock(); | ||
721 | return err; | ||
722 | } | ||
723 | rtnl_unlock(); | ||
724 | |||
725 | return 0; | ||
726 | } | ||
diff --git a/net/tipc/bearer.h b/net/tipc/bearer.h index 78fccc49de23..a87e8c78d862 100644 --- a/net/tipc/bearer.h +++ b/net/tipc/bearer.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/bearer.h: Include file for TIPC bearer code | 2 | * net/tipc/bearer.h: Include file for TIPC bearer code |
3 | * | 3 | * |
4 | * Copyright (c) 1996-2006, 2013, Ericsson AB | 4 | * Copyright (c) 1996-2006, 2013-2014, Ericsson AB |
5 | * Copyright (c) 2005, 2010-2011, Wind River Systems | 5 | * Copyright (c) 2005, 2010-2011, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -38,6 +38,8 @@ | |||
38 | #define _TIPC_BEARER_H | 38 | #define _TIPC_BEARER_H |
39 | 39 | ||
40 | #include "bcast.h" | 40 | #include "bcast.h" |
41 | #include "netlink.h" | ||
42 | #include <net/genetlink.h> | ||
41 | 43 | ||
42 | #define MAX_BEARERS 2 | 44 | #define MAX_BEARERS 2 |
43 | #define MAX_MEDIA 2 | 45 | #define MAX_MEDIA 2 |
@@ -176,6 +178,9 @@ extern struct tipc_media eth_media_info; | |||
176 | extern struct tipc_media ib_media_info; | 178 | extern struct tipc_media ib_media_info; |
177 | #endif | 179 | #endif |
178 | 180 | ||
181 | int tipc_nl_bearer_disable(struct sk_buff *skb, struct genl_info *info); | ||
182 | int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info); | ||
183 | |||
179 | int tipc_media_set_priority(const char *name, u32 new_value); | 184 | int tipc_media_set_priority(const char *name, u32 new_value); |
180 | int tipc_media_set_window(const char *name, u32 new_value); | 185 | int tipc_media_set_window(const char *name, u32 new_value); |
181 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); | 186 | void tipc_media_addr_printf(char *buf, int len, struct tipc_media_addr *a); |
diff --git a/net/tipc/core.h b/net/tipc/core.h index f773b148722f..b578b10feefa 100644 --- a/net/tipc/core.h +++ b/net/tipc/core.h | |||
@@ -41,6 +41,7 @@ | |||
41 | 41 | ||
42 | #include <linux/tipc.h> | 42 | #include <linux/tipc.h> |
43 | #include <linux/tipc_config.h> | 43 | #include <linux/tipc_config.h> |
44 | #include <linux/tipc_netlink.h> | ||
44 | #include <linux/types.h> | 45 | #include <linux/types.h> |
45 | #include <linux/kernel.h> | 46 | #include <linux/kernel.h> |
46 | #include <linux/errno.h> | 47 | #include <linux/errno.h> |
diff --git a/net/tipc/link.c b/net/tipc/link.c index 7cf8004577f1..e7f365012bd1 100644 --- a/net/tipc/link.c +++ b/net/tipc/link.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include "name_distr.h" | 40 | #include "name_distr.h" |
41 | #include "discover.h" | 41 | #include "discover.h" |
42 | #include "config.h" | 42 | #include "config.h" |
43 | #include "netlink.h" | ||
43 | 44 | ||
44 | #include <linux/pkt_sched.h> | 45 | #include <linux/pkt_sched.h> |
45 | 46 | ||
@@ -50,6 +51,14 @@ static const char *link_co_err = "Link changeover error, "; | |||
50 | static const char *link_rst_msg = "Resetting link "; | 51 | static const char *link_rst_msg = "Resetting link "; |
51 | static const char *link_unk_evt = "Unknown link event "; | 52 | static const char *link_unk_evt = "Unknown link event "; |
52 | 53 | ||
54 | /* Properties valid for media, bearar and link */ | ||
55 | static const struct nla_policy tipc_nl_prop_policy[TIPC_NLA_PROP_MAX + 1] = { | ||
56 | [TIPC_NLA_PROP_UNSPEC] = { .type = NLA_UNSPEC }, | ||
57 | [TIPC_NLA_PROP_PRIO] = { .type = NLA_U32 }, | ||
58 | [TIPC_NLA_PROP_TOL] = { .type = NLA_U32 }, | ||
59 | [TIPC_NLA_PROP_WIN] = { .type = NLA_U32 } | ||
60 | }; | ||
61 | |||
53 | /* | 62 | /* |
54 | * Out-of-range value for link session numbers | 63 | * Out-of-range value for link session numbers |
55 | */ | 64 | */ |
@@ -2376,3 +2385,41 @@ static void link_print(struct tipc_link *l_ptr, const char *str) | |||
2376 | else | 2385 | else |
2377 | pr_cont("\n"); | 2386 | pr_cont("\n"); |
2378 | } | 2387 | } |
2388 | |||
2389 | /* Parse and validate nested (link) properties valid for media, bearer and link | ||
2390 | */ | ||
2391 | int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[]) | ||
2392 | { | ||
2393 | int err; | ||
2394 | |||
2395 | err = nla_parse_nested(props, TIPC_NLA_PROP_MAX, prop, | ||
2396 | tipc_nl_prop_policy); | ||
2397 | if (err) | ||
2398 | return err; | ||
2399 | |||
2400 | if (props[TIPC_NLA_PROP_PRIO]) { | ||
2401 | u32 prio; | ||
2402 | |||
2403 | prio = nla_get_u32(props[TIPC_NLA_PROP_PRIO]); | ||
2404 | if (prio > TIPC_MAX_LINK_PRI) | ||
2405 | return -EINVAL; | ||
2406 | } | ||
2407 | |||
2408 | if (props[TIPC_NLA_PROP_TOL]) { | ||
2409 | u32 tol; | ||
2410 | |||
2411 | tol = nla_get_u32(props[TIPC_NLA_PROP_TOL]); | ||
2412 | if ((tol < TIPC_MIN_LINK_TOL) || (tol > TIPC_MAX_LINK_TOL)) | ||
2413 | return -EINVAL; | ||
2414 | } | ||
2415 | |||
2416 | if (props[TIPC_NLA_PROP_WIN]) { | ||
2417 | u32 win; | ||
2418 | |||
2419 | win = nla_get_u32(props[TIPC_NLA_PROP_WIN]); | ||
2420 | if ((win < TIPC_MIN_LINK_WIN) || (win > TIPC_MAX_LINK_WIN)) | ||
2421 | return -EINVAL; | ||
2422 | } | ||
2423 | |||
2424 | return 0; | ||
2425 | } | ||
diff --git a/net/tipc/link.h b/net/tipc/link.h index b567a3427fda..4338294f20d4 100644 --- a/net/tipc/link.h +++ b/net/tipc/link.h | |||
@@ -37,6 +37,7 @@ | |||
37 | #ifndef _TIPC_LINK_H | 37 | #ifndef _TIPC_LINK_H |
38 | #define _TIPC_LINK_H | 38 | #define _TIPC_LINK_H |
39 | 39 | ||
40 | #include <net/genetlink.h> | ||
40 | #include "msg.h" | 41 | #include "msg.h" |
41 | #include "node.h" | 42 | #include "node.h" |
42 | 43 | ||
@@ -239,6 +240,8 @@ void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window); | |||
239 | void tipc_link_retransmit(struct tipc_link *l_ptr, | 240 | void tipc_link_retransmit(struct tipc_link *l_ptr, |
240 | struct sk_buff *start, u32 retransmits); | 241 | struct sk_buff *start, u32 retransmits); |
241 | 242 | ||
243 | int tipc_nl_parse_link_prop(struct nlattr *prop, struct nlattr *props[]); | ||
244 | |||
242 | /* | 245 | /* |
243 | * Link sequence number manipulation routines (uses modulo 2**16 arithmetic) | 246 | * Link sequence number manipulation routines (uses modulo 2**16 arithmetic) |
244 | */ | 247 | */ |
diff --git a/net/tipc/netlink.c b/net/tipc/netlink.c index ad844d365340..af506ae0a129 100644 --- a/net/tipc/netlink.c +++ b/net/tipc/netlink.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * net/tipc/netlink.c: TIPC configuration handling | 2 | * net/tipc/netlink.c: TIPC configuration handling |
3 | * | 3 | * |
4 | * Copyright (c) 2005-2006, Ericsson AB | 4 | * Copyright (c) 2005-2006, 2014, Ericsson AB |
5 | * Copyright (c) 2005-2007, Wind River Systems | 5 | * Copyright (c) 2005-2007, Wind River Systems |
6 | * All rights reserved. | 6 | * All rights reserved. |
7 | * | 7 | * |
@@ -36,6 +36,7 @@ | |||
36 | 36 | ||
37 | #include "core.h" | 37 | #include "core.h" |
38 | #include "config.h" | 38 | #include "config.h" |
39 | #include "bearer.h" | ||
39 | #include <net/genetlink.h> | 40 | #include <net/genetlink.h> |
40 | 41 | ||
41 | static int handle_cmd(struct sk_buff *skb, struct genl_info *info) | 42 | static int handle_cmd(struct sk_buff *skb, struct genl_info *info) |
@@ -68,6 +69,12 @@ static int handle_cmd(struct sk_buff *skb, struct genl_info *info) | |||
68 | return 0; | 69 | return 0; |
69 | } | 70 | } |
70 | 71 | ||
72 | static const struct nla_policy tipc_nl_policy[TIPC_NLA_MAX + 1] = { | ||
73 | [TIPC_NLA_UNSPEC] = { .type = NLA_UNSPEC, }, | ||
74 | [TIPC_NLA_BEARER] = { .type = NLA_NESTED, }, | ||
75 | }; | ||
76 | |||
77 | /* Legacy ASCII API */ | ||
71 | static struct genl_family tipc_genl_family = { | 78 | static struct genl_family tipc_genl_family = { |
72 | .id = GENL_ID_GENERATE, | 79 | .id = GENL_ID_GENERATE, |
73 | .name = TIPC_GENL_NAME, | 80 | .name = TIPC_GENL_NAME, |
@@ -76,6 +83,7 @@ static struct genl_family tipc_genl_family = { | |||
76 | .maxattr = 0, | 83 | .maxattr = 0, |
77 | }; | 84 | }; |
78 | 85 | ||
86 | /* Legacy ASCII API */ | ||
79 | static struct genl_ops tipc_genl_ops[] = { | 87 | static struct genl_ops tipc_genl_ops[] = { |
80 | { | 88 | { |
81 | .cmd = TIPC_GENL_CMD, | 89 | .cmd = TIPC_GENL_CMD, |
@@ -83,12 +91,43 @@ static struct genl_ops tipc_genl_ops[] = { | |||
83 | }, | 91 | }, |
84 | }; | 92 | }; |
85 | 93 | ||
94 | /* Users of the legacy API (tipc-config) can't handle that we add operations, | ||
95 | * so we have a separate genl handling for the new API. | ||
96 | */ | ||
97 | struct genl_family tipc_genl_v2_family = { | ||
98 | .id = GENL_ID_GENERATE, | ||
99 | .name = TIPC_GENL_V2_NAME, | ||
100 | .version = TIPC_GENL_V2_VERSION, | ||
101 | .hdrsize = 0, | ||
102 | .maxattr = TIPC_NLA_MAX, | ||
103 | }; | ||
104 | |||
105 | static const struct genl_ops tipc_genl_v2_ops[] = { | ||
106 | { | ||
107 | .cmd = TIPC_NL_BEARER_DISABLE, | ||
108 | .doit = tipc_nl_bearer_disable, | ||
109 | .policy = tipc_nl_policy, | ||
110 | }, | ||
111 | { | ||
112 | .cmd = TIPC_NL_BEARER_ENABLE, | ||
113 | .doit = tipc_nl_bearer_enable, | ||
114 | .policy = tipc_nl_policy, | ||
115 | } | ||
116 | }; | ||
117 | |||
86 | int tipc_netlink_start(void) | 118 | int tipc_netlink_start(void) |
87 | { | 119 | { |
88 | int res; | 120 | int res; |
89 | 121 | ||
90 | res = genl_register_family_with_ops(&tipc_genl_family, tipc_genl_ops); | 122 | res = genl_register_family_with_ops(&tipc_genl_family, tipc_genl_ops); |
91 | if (res) { | 123 | if (res) { |
124 | pr_err("Failed to register legacy interface\n"); | ||
125 | return res; | ||
126 | } | ||
127 | |||
128 | res = genl_register_family_with_ops(&tipc_genl_v2_family, | ||
129 | tipc_genl_v2_ops); | ||
130 | if (res) { | ||
92 | pr_err("Failed to register netlink interface\n"); | 131 | pr_err("Failed to register netlink interface\n"); |
93 | return res; | 132 | return res; |
94 | } | 133 | } |
@@ -98,4 +137,5 @@ int tipc_netlink_start(void) | |||
98 | void tipc_netlink_stop(void) | 137 | void tipc_netlink_stop(void) |
99 | { | 138 | { |
100 | genl_unregister_family(&tipc_genl_family); | 139 | genl_unregister_family(&tipc_genl_family); |
140 | genl_unregister_family(&tipc_genl_v2_family); | ||
101 | } | 141 | } |
diff --git a/net/tipc/netlink.h b/net/tipc/netlink.h new file mode 100644 index 000000000000..e9980c0e2207 --- /dev/null +++ b/net/tipc/netlink.h | |||
@@ -0,0 +1,41 @@ | |||
1 | /* | ||
2 | * net/tipc/netlink.h: Include file for TIPC netlink code | ||
3 | * | ||
4 | * Copyright (c) 2014, Ericsson AB | ||
5 | * All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions are met: | ||
9 | * | ||
10 | * 1. Redistributions of source code must retain the above copyright | ||
11 | * notice, this list of conditions and the following disclaimer. | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in the | ||
14 | * documentation and/or other materials provided with the distribution. | ||
15 | * 3. Neither the names of the copyright holders nor the names of its | ||
16 | * contributors may be used to endorse or promote products derived from | ||
17 | * this software without specific prior written permission. | ||
18 | * | ||
19 | * Alternatively, this software may be distributed under the terms of the | ||
20 | * GNU General Public License ("GPL") version 2 as published by the Free | ||
21 | * Software Foundation. | ||
22 | * | ||
23 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
24 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | ||
27 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
33 | * POSSIBILITY OF SUCH DAMAGE. | ||
34 | */ | ||
35 | |||
36 | #ifndef _TIPC_NETLINK_H | ||
37 | #define _TIPC_NETLINK_H | ||
38 | |||
39 | extern struct genl_family tipc_genl_v2_family; | ||
40 | |||
41 | #endif | ||