Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tipc: convert legacy nl bearer enable/disable to nl compat

Introduce a framework for transcoding legacy nl action into actions
(.doit) calls from the new nl API. This is done by converting the
incoming TLV data into netlink data with nested netlink attributes.
Unfortunately due to the randomness of the legacy API we can't do this
generically so each legacy netlink command requires a specific
transcoding recipe. In this case for bearer enable and bearer disable.

Convert TIPC_CMD_ENABLE_BEARER and TIPC_CMD_DISABLE_BEARER into doit
compat calls.

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>

authored by

Richard Alpe and committed by
David S. Miller
9ab15465 d0796d1e

+154 -57
+5
include/uapi/linux/tipc_config.h
··· 277 277 return ntohs(tlv->tlv_len); 278 278 } 279 279 280 + static inline int TLV_CHECK_TYPE(struct tlv_desc *tlv, __u16 type) 281 + { 282 + return (ntohs(tlv->tlv_type) == type); 283 + } 284 + 280 285 static inline int TLV_SET(void *tlv, __u16 type, void *data, __u16 len) 281 286 { 282 287 struct tlv_desc *tlv_ptr;
+5 -21
net/tipc/bearer.c
··· 236 236 /** 237 237 * tipc_enable_bearer - enable bearer with the given name 238 238 */ 239 - int tipc_enable_bearer(struct net *net, const char *name, u32 disc_domain, 240 - u32 priority) 239 + static int tipc_enable_bearer(struct net *net, const char *name, 240 + u32 disc_domain, u32 priority) 241 241 { 242 242 struct tipc_net *tn = net_generic(net, tipc_net_id); 243 243 struct tipc_bearer *b_ptr; ··· 391 391 } 392 392 } 393 393 kfree_rcu(b_ptr, rcu); 394 - } 395 - 396 - int tipc_disable_bearer(struct net *net, const char *name) 397 - { 398 - struct tipc_bearer *b_ptr; 399 - int res; 400 - 401 - b_ptr = tipc_bearer_find(net, name); 402 - if (b_ptr == NULL) { 403 - pr_warn("Attempt to disable unknown bearer <%s>\n", name); 404 - res = -EINVAL; 405 - } else { 406 - bearer_disable(net, b_ptr, false); 407 - res = 0; 408 - } 409 - return res; 410 394 } 411 395 412 396 int tipc_enable_l2_media(struct net *net, struct tipc_bearer *b) ··· 740 756 char *name; 741 757 struct tipc_bearer *bearer; 742 758 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; 743 - struct net *net = genl_info_net(info); 759 + struct net *net = sock_net(skb->sk); 744 760 745 761 if (!info->attrs[TIPC_NLA_BEARER]) 746 762 return -EINVAL; ··· 771 787 772 788 int tipc_nl_bearer_enable(struct sk_buff *skb, struct genl_info *info) 773 789 { 774 - struct net *net = genl_info_net(info); 775 - struct tipc_net *tn = net_generic(net, tipc_net_id); 776 790 int err; 777 791 char *bearer; 778 792 struct nlattr *attrs[TIPC_NLA_BEARER_MAX + 1]; 793 + struct net *net = sock_net(skb->sk); 794 + struct tipc_net *tn = net_generic(net, tipc_net_id); 779 795 u32 domain; 780 796 u32 prio; 781 797
-3
net/tipc/bearer.h
··· 173 173 */ 174 174 175 175 void tipc_rcv(struct net *net, struct sk_buff *skb, struct tipc_bearer *b_ptr); 176 - int tipc_enable_bearer(struct net *net, const char *bearer_name, 177 - u32 disc_domain, u32 priority); 178 - int tipc_disable_bearer(struct net *net, const char *name); 179 176 180 177 /* 181 178 * Routines made available to TIPC by supported media types
-33
net/tipc/config.c
··· 134 134 return buf; 135 135 } 136 136 137 - static struct sk_buff *cfg_enable_bearer(struct net *net) 138 - { 139 - struct tipc_bearer_config *args; 140 - 141 - if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_CONFIG)) 142 - return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); 143 - 144 - args = (struct tipc_bearer_config *)TLV_DATA(req_tlv_area); 145 - if (tipc_enable_bearer(net, args->name, 146 - ntohl(args->disc_domain), 147 - ntohl(args->priority))) 148 - return tipc_cfg_reply_error_string("unable to enable bearer"); 149 - 150 - return tipc_cfg_reply_none(); 151 - } 152 - 153 - static struct sk_buff *cfg_disable_bearer(struct net *net) 154 - { 155 - if (!TLV_CHECK(req_tlv_area, req_tlv_space, TIPC_TLV_BEARER_NAME)) 156 - return tipc_cfg_reply_error_string(TIPC_CFG_TLV_ERROR); 157 - 158 - if (tipc_disable_bearer(net, (char *)TLV_DATA(req_tlv_area))) 159 - return tipc_cfg_reply_error_string("unable to disable bearer"); 160 - 161 - return tipc_cfg_reply_none(); 162 - } 163 - 164 137 static struct sk_buff *cfg_set_own_addr(struct net *net) 165 138 { 166 139 struct tipc_net *tn = net_generic(net, tipc_net_id); ··· 239 266 case TIPC_CMD_SET_LINK_WINDOW: 240 267 rep_tlv_buf = tipc_link_cmd_config(net, req_tlv_area, 241 268 req_tlv_space, cmd); 242 - break; 243 - case TIPC_CMD_ENABLE_BEARER: 244 - rep_tlv_buf = cfg_enable_bearer(net); 245 - break; 246 - case TIPC_CMD_DISABLE_BEARER: 247 - rep_tlv_buf = cfg_disable_bearer(net); 248 269 break; 249 270 case TIPC_CMD_SET_NODE_ADDR: 250 271 rep_tlv_buf = cfg_set_own_addr(net);