tipc: some small patches
Subsystems (3)
v2 cover tipc: some small patches
Some small and relatively straightforward patches. With exception of the two first ones they are all unrelated and address minor issues.
v2: update of v1 (http://patchwork.ozlabs.org/patch/277404/)
-added commit to use memcpy_fromiovec on user data as per v1 feedback -updated sparse fix commit to drop chunks covered by above commit -added new commit that greatly simplifies the link lookup routine
Erik Hugne (1):
tipc: simplify the link lookup routine
Ying Xue (7):
tipc: don't use memcpy to copy from user space
tipc: remove iovec length parameter from all sending functions
tipc: silence sparse warnings
tipc: make bearer and media naming consistent
tipc: avoid unnecessary lookup for tipc bearer instance
tipc: correct return value of recv_msg routine
tipc: correct return value of link_cmd_set_value routine
net/tipc/bearer.c | 18 ++---- net/tipc/bearer.h | 10 +-- net/tipc/eth_media.c | 68 ++++++++++---------- net/tipc/ib_media.c | 58 +++++++++--------- net/tipc/link.c | 167 +++++++++++++------------------------------------- net/tipc/link.h | 4 +- net/tipc/msg.c | 27 ++++---- net/tipc/msg.h | 3 +- net/tipc/port.c | 66 ++++++++------------ net/tipc/port.h | 16 ++--- net/tipc/socket.c | 12 ++-- 11 files changed, 167 insertions(+), 282 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v2 1/8 tipc: don't use memcpy to copy from user space
From: Ying Xue <[email protected]>
tipc_msg_build() calls skb_copy_to_linear_data_offset() to copy data from user space to kernel space. However, the latter function does in its turn call memcpy() to perform the actual copying. This poses an obvious security and robustness risk, since memcpy() never makes any validity check on the pointer it is copying from.
To correct this, we the replace the offending function call with a call to memcpy_fromiovecend(), which uses copy_from_user() to perform the copying.
--- net/tipc/msg.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
net/tipc/msg.c +9 -13
@@ -76,10 +76,11 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect, u32 num_sect, unsigned int total_len, int max_size, struct sk_buff **buf) { - int dsz, sz, hsz, pos, res, cnt; + int dsz, sz, hsz; +unsigned char *to; dsz = total_len; - pos = hsz =msg_hdr_sz (hdr); + hsz =msg_hdr_sz (hdr); sz = hsz + dsz;msg_set_size (hdr, sz);if (unlikely (sz > max_size)) {
@@ -91,16 +92,11 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,if (!(*buf))return -ENOMEM ;skb_copy_to_linear_data (*buf, hdr, hsz); -for (res =1 , cnt =0 ; res && (cnt < num_sect); cnt++) { -skb_copy_to_linear_data_offset (*buf, pos, - msg_sect[cnt].iov_base, - msg_sect[cnt].iov_len); - pos += msg_sect[cnt].iov_len; + to = (*buf)->data + hsz; +if (total_len &&memcpy_fromiovecend (to, msg_sect,0 , dsz)) { +kfree_skb (*buf); + *buf =NULL ; +return -EFAULT ; } -if (likely (res)) -return dsz; - -kfree_skb (*buf); - *buf =NULL ; -return -EFAULT ; +return dsz; }
Signature · 1 line
1.7.9.5
PATCH v2 2/8 tipc: remove iovec length parameter from all sending functions
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
tipc_msg_build() now copies message data from iovec to skb_buff using memcpy_fromiovecend(), which doesn't need to be passed the iovec length to perform the copying.
So we remove the parameter indicating iovec length in all functions where TIPC messages are built and sent.
--- net/tipc/link.c | 25 ++++++++------------ net/tipc/link.h | 4 +--- net/tipc/msg.c | 7 +++--- net/tipc/msg.h | 3 +-- net/tipc/port.c | 66 ++++++++++++++++++++++------------------------------- net/tipc/port.h | 16 +++++-------- net/tipc/socket.c | 6 +---- 7 files changed, 49 insertions(+), 78 deletions(-)
net/tipc/link.c +10 -15
@@ -97,8 +97,7 @@ static int link_recv_changeover_msg(struct tipc_link **l_ptr,static void link_set_supervision_props (struct tipc_link *l_ptr,u32 tolerance);static int link_send_sections_long (struct tipc_port *sender,struct iovec const *msg_sect, -u32 num_sect,unsigned int total_len, -u32 destnode); +unsigned int len,u32 destnode);static void link_state_event (struct tipc_link *l_ptr,u32 event);static void link_reset_statistics (struct tipc_link *l_ptr);static void link_print (struct tipc_link *l_ptr,const char *str);
@@ -1065,8 +1064,7 @@ static int link_send_buf_fast(struct tipc_link *l_ptr, struct sk_buff *buf,*/ int tipc_link_send_sections_fast (struct tipc_port *sender,struct iovec const *msg_sect, -const u32 num_sect,unsigned int total_len, -u32 destaddr) +unsigned int len,u32 destaddr) {struct tipc_msg *hdr = &sender->phdr;struct tipc_link *l_ptr;
@@ -1080,8 +1078,7 @@ again:* Try building message using port's max_pkt hint. * (Must not hold any locks while building message.) */ - res =tipc_msg_build (hdr, msg_sect, num_sect, total_len, - sender->max_pkt, &buf); + res =tipc_msg_build (hdr, msg_sect, len, sender->max_pkt, &buf);/* Exit if build request was invalid */ if (unlikely (res <0 ))return res;
@@ -1121,8 +1118,7 @@ exit:if ((msg_hdr_sz (hdr) + res) <= sender->max_pkt) goto again; -return link_send_sections_long (sender, msg_sect, - num_sect, total_len, +return link_send_sections_long (sender, msg_sect, len, destaddr); }tipc_node_unlock (node);
@@ -1133,8 +1129,8 @@ exit:if (buf)return tipc_reject_msg (buf,TIPC_ERR_NO_NODE );if (res >=0 ) -return tipc_port_reject_sections (sender, hdr, msg_sect, num_sect, - total_len,TIPC_ERR_NO_NODE ); +return tipc_port_reject_sections (sender, hdr, msg_sect, + len,TIPC_ERR_NO_NODE );return res; }
@@ -1154,13 +1150,12 @@ exit:*/ static int link_send_sections_long (struct tipc_port *sender,struct iovec const *msg_sect, -u32 num_sect,unsigned int total_len, -u32 destaddr) +unsigned int len,u32 destaddr) {struct tipc_link *l_ptr;struct tipc_node *node;struct tipc_msg *hdr = &sender->phdr; -u32 dsz = total_len; +u32 dsz = len;u32 max_pkt, fragm_sz, rest;struct tipc_msg fragm_hdr;struct sk_buff *buf, *buf_chain, *prev;
@@ -1283,8 +1278,8 @@ reject: buf = buf_chain->next;kfree_skb (buf_chain); } -return tipc_port_reject_sections (sender, hdr, msg_sect, num_sect, - total_len,TIPC_ERR_NO_NODE ); +return tipc_port_reject_sections (sender, hdr, msg_sect, + len,TIPC_ERR_NO_NODE ); }/* Append chain of fragments to send queue & send them */
net/tipc/link.h +1 -3
@@ -227,9 +227,7 @@ int tipc_link_send_buf(struct tipc_link *l_ptr, struct sk_buff *buf);u32 tipc_link_get_max_pkt (u32 dest,u32 selector);int tipc_link_send_sections_fast (struct tipc_port *sender,struct iovec const *msg_sect, -const u32 num_sect, -unsigned int total_len, -u32 destnode); +unsigned int len,u32 destnode);void tipc_link_recv_bundle (struct sk_buff *buf); int tipc_link_recv_fragment(struct sk_buff **pending, struct sk_buff **fb,
net/tipc/msg.c +3 -4
@@ -73,13 +73,12 @@ void tipc_msg_init(struct tipc_msg *m, u32 user, u32 type, u32 hsize,* Returns message data size or errno */ int tipc_msg_build (struct tipc_msg *hdr,struct iovec const *msg_sect, -u32 num_sect,unsigned int total_len,int max_size, -struct sk_buff **buf) +unsigned int len,int max_size,struct sk_buff **buf) {int dsz, sz, hsz;unsigned char *to; - dsz = total_len; + dsz = len; hsz =msg_hdr_sz (hdr); sz = hsz + dsz;msg_set_size (hdr, sz);
@@ -93,7 +92,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,return -ENOMEM ;skb_copy_to_linear_data (*buf, hdr, hsz); to = (*buf)->data + hsz; -if (total_len &&memcpy_fromiovecend (to, msg_sect,0 , dsz)) { +if (len &&memcpy_fromiovecend (to, msg_sect,0 , dsz)) {kfree_skb (*buf); *buf =NULL ;return -EFAULT ;
net/tipc/msg.h +1 -2
@@ -722,6 +722,5 @@ u32 tipc_msg_tot_importance(struct tipc_msg *m);void tipc_msg_init (struct tipc_msg *m,u32 user,u32 type,u32 hsize,u32 destnode);int tipc_msg_build (struct tipc_msg *hdr,struct iovec const *msg_sect, -u32 num_sect,unsigned int total_len,int max_size, -struct sk_buff **buf); +unsigned int len,int max_size,struct sk_buff **buf);#endif
net/tipc/port.c +27 -39
163 lines not on this page · raw message
net/tipc/port.h +6 -10
@@ -151,24 +151,20 @@ int tipc_port_peer_msg(struct tipc_port *p_ptr, struct tipc_msg *msg);* TIPC messaging routines */ int tipc_port_recv_msg (struct sk_buff *buf); -int tipc_send (u32 portref,unsigned int num_sect,struct iovec const *msg_sect, -unsigned int total_len); +int tipc_send (u32 portref,struct iovec const *msg_sect,unsigned int len);int tipc_send2name (u32 portref,struct tipc_name const *name,u32 domain, -unsigned int num_sect,struct iovec const *msg_sect, -unsigned int total_len); +struct iovec const *msg_sect,unsigned int len);int tipc_send2port (u32 portref,struct tipc_portid const *dest, -unsigned int num_sect,struct iovec const *msg_sect, -unsigned int total_len); +struct iovec const *msg_sect,unsigned int len);int tipc_multicast (u32 portref,struct tipc_name_seq const *seq, -unsigned int section_count,struct iovec const *msg, -unsigned int total_len); +struct iovec const *msg,unsigned int len);int tipc_port_reject_sections (struct tipc_port *p_ptr,struct tipc_msg *hdr, -struct iovec const *msg_sect,u32 num_sect, -unsigned int total_len,int err); +struct iovec const *msg_sect,unsigned int len, +int err);struct sk_buff *tipc_port_get_ports (void );void tipc_port_recv_proto_msg (struct sk_buff *buf);void tipc_port_recv_mcast (struct sk_buff *buf,struct tipc_port_list *dp);
net/tipc/socket.c +1 -5
@@ -622,13 +622,11 @@ static int send_msg(struct kiocb *iocb, struct socket *sock, res =tipc_send2name (tport->ref, &dest->addr.name.name, dest->addr.name.domain, - m->msg_iovlen, m->msg_iov, total_len); }else if (dest->addrtype ==TIPC_ADDR_ID ) { res =tipc_send2port (tport->ref, &dest->addr.id, - m->msg_iovlen, m->msg_iov, total_len); }else if (dest->addrtype ==TIPC_ADDR_MCAST ) {
@@ -641,7 +639,6 @@ static int send_msg(struct kiocb *iocb, struct socket *sock,break ; res =tipc_multicast (tport->ref, &dest->addr.nameseq, - m->msg_iovlen, m->msg_iov, total_len); }
@@ -707,8 +704,7 @@ static int send_packet(struct kiocb *iocb, struct socket *sock,break ; } - res =tipc_send (tport->ref, m->msg_iovlen, m->msg_iov, - total_len); + res =tipc_send (tport->ref, m->msg_iov, total_len);if (likely (res != -ELINKCONG ))break ;if (timeout_val <=0L ) {
Signature · 1 line
1.7.9.5
PATCH v2 3/8 tipc: silence sparse warnings
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
Eliminate below sparse warnings:
net/tipc/link.c:1210:37: warning: cast removes address space of expression net/tipc/link.c:1218:59: warning: incorrect type in argument 2 (different address spaces)net/tipc/link.c:1218:59: expected void const [noderef] <asn:1>*fromnet/tipc/link.c:1218:59: got unsigned char const [usertype] *[assigned] sect_crsnet/tipc/socket.c:341:49: warning: Using plain integer as NULL pointer net/tipc/socket.c:1371:36: warning: Using plain integer as NULL pointer net/tipc/socket.c:1694:57: warning: Using plain integer as NULL pointer
--- net/tipc/link.c | 4 ++-- net/tipc/socket.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
net/tipc/link.c +2 -2
@@ -1160,7 +1160,7 @@ static int link_send_sections_long(struct tipc_port *sender,struct tipc_msg fragm_hdr;struct sk_buff *buf, *buf_chain, *prev;u32 fragm_crs, fragm_rest, hsz, sect_rest; -const unchar *sect_crs; +const unchar __user *sect_crs;int curr_sect;u32 fragm_no;int res =0 ;
@@ -1202,7 +1202,7 @@ again:if (!sect_rest) { sect_rest = msg_sect[++curr_sect].iov_len; - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base; + sect_crs = msg_sect[curr_sect].iov_base; }if (sect_rest < fragm_rest)
net/tipc/socket.c +3 -3
@@ -338,7 +338,7 @@ static int release(struct socket *sock) buf =__skb_dequeue (&sk->sk_receive_queue);if (buf ==NULL )break ; -if (TIPC_SKB_CB (buf)->handle !=0 ) +if (TIPC_SKB_CB (buf)->handle !=NULL )kfree_skb (buf);else { if ((sock->state == SS_CONNECTING) ||
@@ -1364,7 +1364,7 @@ static u32 filter_rcv(struct sock *sk, struct sk_buff *buf)return TIPC_ERR_OVERLOAD ;/* Enqueue message */ -TIPC_SKB_CB (buf)->handle =0 ; +TIPC_SKB_CB (buf)->handle =NULL ;__skb_queue_tail (&sk->sk_receive_queue, buf);skb_set_owner_r (buf, sk);
@@ -1687,7 +1687,7 @@ restart:/* Disconnect and send a 'FIN+' or 'FIN-' message to peer */ buf =__skb_dequeue (&sk->sk_receive_queue);if (buf) { -if (TIPC_SKB_CB (buf)->handle !=0 ) { +if (TIPC_SKB_CB (buf)->handle !=NULL ) {kfree_skb (buf); goto restart; }
Signature · 1 line
1.7.9.5
PATCH v2 4/8 tipc: make bearer and media naming consistent
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
TIPC 'bearer' exists as an abstract concept, while 'media' is deemed a specific implementation of a bearer, such as Ethernet or Infiniband media. When a component inside TIPC wants to control a specific media, it only needs to access the generic bearer API to achieve this. However, in the current media implementations, the 'bearer' name is also extensively used in media specific function and variable names.
This may create confusion, so we choose to replace the term 'bearer' with 'media' in all function names, variable names, and prefixes where this is what really is meant.
Note that this change is cosmetic only, and no runtime behaviour changes are made here.
--- net/tipc/bearer.c | 4 ++-- net/tipc/bearer.h | 8 ++++---- net/tipc/eth_media.c | 56 +++++++++++++++++++++++++------------------------- net/tipc/ib_media.c | 46 ++++++++++++++++++++--------------------- 4 files changed, 57 insertions(+), 57 deletions(-)
net/tipc/bearer.c +2 -2
@@ -387,7 +387,7 @@ restart: b_ptr = &tipc_bearers[bearer_id];strcpy (b_ptr->name, name); - res = m_ptr->enable_bearer (b_ptr); + res = m_ptr->enable_media (b_ptr);if (res) {pr_warn ("Bearer <%s> rejected, enable failure (%d)\n" , name, -res);
@@ -465,7 +465,7 @@ static void bearer_disable(struct tipc_bearer *b_ptr)pr_info ("Disabling bearer <%s>\n" , b_ptr->name);spin_lock_bh (&b_ptr->lock); b_ptr->blocked =1 ; - b_ptr->media->disable_bearer (b_ptr); + b_ptr->media->disable_media (b_ptr);list_for_each_entry_safe (l_ptr, temp_l_ptr, &b_ptr->links, link_list) {tipc_link_delete (l_ptr); }
net/tipc/bearer.h +4 -4
@@ -75,8 +75,8 @@ struct tipc_bearer;/** * struct tipc_media - TIPC media information available to internal users * @send_msg: routine which handles buffer transmission -* @enable_bearer: routine which enables a bearer -* @disable_bearer: routine which disables a bearer +* @enable_media: routine which enables a media +* @disable_media: routine which disables a media * @addr2str: routine which converts media address to string * @addr2msg: routine which converts media address to protocol message area * @msg2addr: routine which converts media address from protocol message area
@@ -91,8 +91,8 @@ struct tipc_media {int (*send_msg)(struct sk_buff *buf,struct tipc_bearer *b_ptr,struct tipc_media_addr *dest); -int (*enable_bearer)(struct tipc_bearer *b_ptr); -void (*disable_bearer)(struct tipc_bearer *b_ptr); +int (*enable_media)(struct tipc_bearer *b_ptr); +void (*disable_media)(struct tipc_bearer *b_ptr);int (*addr2str)(struct tipc_media_addr *a,char *str_buf,int str_size);int (*addr2msg)(struct tipc_media_addr *a,char *msg_area); int (*msg2addr)(const struct tipc_bearer *b_ptr,
net/tipc/eth_media.c +28 -28
154 lines not on this page · raw message
net/tipc/ib_media.c +23 -23
129 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 5/8 tipc: avoid unnecessary lookup for tipc bearer instance
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
tipc_block_bearer() currently takes a bearer name (const char*) as argument. This requires the function to make a lookup to find the pointer to the corresponding bearer struct. In the current code base this is not necessary, since the only two callers (tipc_continue(),recv_notification()) already have validated copies of this pointer, and hence can pass it directly in the function call.
We change tipc_block_bearer() to directly take struct tipc_bearer* as argument instead.
--- net/tipc/bearer.c | 14 +++----------- net/tipc/bearer.h | 2 +- net/tipc/eth_media.c | 6 +++--- net/tipc/ib_media.c | 6 +++--- 4 files changed, 10 insertions(+), 18 deletions(-)
net/tipc/bearer.c +3 -11
@@ -420,23 +420,15 @@ exit: }/** -* tipc_block_bearer - Block the bearer with the given name, and reset all its links +* tipc_block_bearer - Block the bearer, and reset all its links */ -int tipc_block_bearer (const char *name) +int tipc_block_bearer (struct tipc_bearer *b_ptr) { -struct tipc_bearer *b_ptr =NULL ;struct tipc_link *l_ptr;struct tipc_link *temp_l_ptr;read_lock_bh (&tipc_net_lock); - b_ptr =tipc_bearer_find (name); -if (!b_ptr) { -pr_warn ("Attempt to block unknown bearer <%s>\n" , name); -read_unlock_bh (&tipc_net_lock); -return -EINVAL ; - } - -pr_info ("Blocking bearer <%s>\n" , name); +pr_info ("Blocking bearer <%s>\n" , b_ptr->name);spin_lock_bh (&b_ptr->lock); b_ptr->blocked =1 ;list_for_each_entry_safe (l_ptr, temp_l_ptr, &b_ptr->links, link_list) {
net/tipc/bearer.h +1 -1
@@ -163,7 +163,7 @@ int tipc_register_media(struct tipc_media *m_ptr);void tipc_recv_msg (struct sk_buff *buf,struct tipc_bearer *tb_ptr); -int tipc_block_bearer (const char *name); +int tipc_block_bearer (struct tipc_bearer *b_ptr);void tipc_continue (struct tipc_bearer *tb_ptr);int tipc_enable_bearer (const char *bearer_name,u32 disc_domain,u32 priority);
net/tipc/eth_media.c +3 -3
@@ -265,17 +265,17 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,if (netif_carrier_ok (dev))tipc_continue (eb_ptr->bearer);else -tipc_block_bearer (eb_ptr->bearer->name); +tipc_block_bearer (eb_ptr->bearer);break ;case NETDEV_UP :tipc_continue (eb_ptr->bearer);break ;case NETDEV_DOWN : -tipc_block_bearer (eb_ptr->bearer->name); +tipc_block_bearer (eb_ptr->bearer);break ;case NETDEV_CHANGEMTU :case NETDEV_CHANGEADDR : -tipc_block_bearer (eb_ptr->bearer->name); +tipc_block_bearer (eb_ptr->bearer);tipc_continue (eb_ptr->bearer);break ;case NETDEV_UNREGISTER :
net/tipc/ib_media.c +3 -3
@@ -258,17 +258,17 @@ static int recv_notification(struct notifier_block *nb, unsigned long evt,if (netif_carrier_ok (dev))tipc_continue (ib_ptr->bearer);else -tipc_block_bearer (ib_ptr->bearer->name); +tipc_block_bearer (ib_ptr->bearer);break ;case NETDEV_UP :tipc_continue (ib_ptr->bearer);break ;case NETDEV_DOWN : -tipc_block_bearer (ib_ptr->bearer->name); +tipc_block_bearer (ib_ptr->bearer);break ;case NETDEV_CHANGEMTU :case NETDEV_CHANGEADDR : -tipc_block_bearer (ib_ptr->bearer->name); +tipc_block_bearer (ib_ptr->bearer);tipc_continue (ib_ptr->bearer);break ;case NETDEV_UNREGISTER :
Signature · 1 line
1.7.9.5
PATCH v2 6/8 tipc: correct return value of recv_msg routine
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
Currently, rcv_msg() always returns zero on a packet delivery upcall from net_device.
To make its behavior more compliant with the way this API should be used, we change this to let it return NET_RX_SUCCESS (which is zero anyway) when it is able to handle the packet, and NET_RX_DROP otherwise. The latter does not imply any functional change, it only enables the driver to keep more accurate statistics about the fate of delivered packets.
--- net/tipc/eth_media.c | 6 +++--- net/tipc/ib_media.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
net/tipc/eth_media.c +3 -3
@@ -132,18 +132,18 @@ static int recv_msg(struct sk_buff *buf, struct net_device *dev,if (!net_eq (dev_net (dev), &init_net)) {kfree_skb (buf); -return 0 ; +return NET_RX_DROP ; }if (likely (eb_ptr->bearer)) {if (likely (buf->pkt_type <=PACKET_BROADCAST )) { buf->next =NULL ;tipc_recv_msg (buf, eb_ptr->bearer); -return 0 ; +return NET_RX_SUCCESS ; } }kfree_skb (buf); -return 0 ; +return NET_RX_DROP ; }/**
net/tipc/ib_media.c +3 -3
@@ -125,18 +125,18 @@ static int recv_msg(struct sk_buff *buf, struct net_device *dev,if (!net_eq (dev_net (dev), &init_net)) {kfree_skb (buf); -return 0 ; +return NET_RX_DROP ; }if (likely (ib_ptr->bearer)) {if (likely (buf->pkt_type <=PACKET_BROADCAST )) { buf->next =NULL ;tipc_recv_msg (buf, ib_ptr->bearer); -return 0 ; +return NET_RX_SUCCESS ; } }kfree_skb (buf); -return 0 ; +return NET_RX_DROP ; }/**
Signature · 1 line
1.7.9.5
PATCH v2 7/8 tipc: correct return value of link_cmd_set_value routine
In reply to Jon MaloyFrom: Ying Xue <[email protected]>
link_cmd_set_value() takes commands for link, bearer and media related configuration. Genereally the function returns 0 when a command is recognized, and -EINVAL when it is not. However, in the switch for link related commands it returns 0 even when the command is unrecognized. This will sometimes make it look as if a failed configuration command has been successful, but has otherwise no negative effects.
We remove this anomaly by returning -EINVAL even for link commands. We also rework all three switches to make them conforming to common kernel coding style.
--- net/tipc/link.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
net/tipc/link.c +19 -9
@@ -2641,6 +2641,7 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)struct tipc_link *l_ptr;struct tipc_bearer *b_ptr;struct tipc_media *m_ptr; +int res =0 ; l_ptr =link_find_link (name, &node);if (l_ptr) {
@@ -2663,9 +2664,12 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)case TIPC_CMD_SET_LINK_WINDOW :tipc_link_set_queue_limits (l_ptr, new_value);break ; +default : + res = -EINVAL ; +break ; }tipc_node_unlock (node); -return 0 ; +return res; } b_ptr =tipc_bearer_find (name);
@@ -2673,15 +2677,18 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)switch (cmd) {case TIPC_CMD_SET_LINK_TOL : b_ptr->tolerance = new_value; -return 0 ; +break ;case TIPC_CMD_SET_LINK_PRI : b_ptr->priority = new_value; -return 0 ; +break ;case TIPC_CMD_SET_LINK_WINDOW : b_ptr->window = new_value; -return 0 ; +break ; +default : + res = -EINVAL ; +break ; } -return -EINVAL ; +return res; } m_ptr =tipc_media_find (name);
@@ -2690,15 +2697,18 @@ static int link_cmd_set_value(const char *name, u32 new_value, u16 cmd)switch (cmd) {case TIPC_CMD_SET_LINK_TOL : m_ptr->tolerance = new_value; -return 0 ; +break ;case TIPC_CMD_SET_LINK_PRI : m_ptr->priority = new_value; -return 0 ; +break ;case TIPC_CMD_SET_LINK_WINDOW : m_ptr->window = new_value; -return 0 ; +break ; +default : + res = -EINVAL ; +break ; } -return -EINVAL ; +return res; } struct sk_buff *tipc_link_cmd_config(const void *req_tlv_area, int req_tlv_space,
Signature · 1 line
1.7.9.5
PATCH v2 8/8 tipc: simplify the link lookup routine
In reply to Jon MaloyFrom: Erik Hugne <[email protected]>
When checking statistics or changing parameters on a link, the link_find_link function is used to locate the link with a given name. The complex method of deconstructing the name into local and remote address/interface is error prone and may fail if the interface names contains special characters. We change the lookup method to iterate over the list of nodes and compare the link names.
--- net/tipc/link.c | 110 +++++++------------------------------------------------ 1 file changed, 13 insertions(+), 97 deletions(-)
net/tipc/link.c +13 -97
@@ -75,20 +75,6 @@ static const char *link_unk_evt = "Unknown link event ";*/ #define START_CHANGEOVER 100000u -/** -* struct tipc_link_name - deconstructed link name -* @addr_local: network address of node at this end -* @if_local: name of interface at this end -* @addr_peer: network address of node at far end -* @if_peer: name of interface at far end -*/ -struct tipc_link_name { -u32 addr_local; -char if_local[TIPC_MAX_IF_NAME ]; -u32 addr_peer; -char if_peer[TIPC_MAX_IF_NAME ]; -}; -static void link_handle_out_of_seq_msg (struct tipc_link *l_ptr,struct sk_buff *buf);static void link_recv_proto_msg (struct tipc_link *l_ptr,struct sk_buff *buf);
@@ -160,72 +146,6 @@ int tipc_link_is_active(struct tipc_link *l_ptr) }/** -* link_name_validate - validate & (optionally) deconstruct tipc_link name -* @name: ptr to link name string -* @name_parts: ptr to area for link name components (or NULL if not needed) -* -* Returns 1 if link name is valid, otherwise 0. -*/ -static int link_name_validate (const char *name, -struct tipc_link_name *name_parts) -{ -char name_copy[TIPC_MAX_LINK_NAME ]; -char *addr_local; -char *if_local; -char *addr_peer; -char *if_peer; -char dummy; -u32 z_local, c_local, n_local; -u32 z_peer, c_peer, n_peer; -u32 if_local_len; -u32 if_peer_len; - -/* copy link name & ensure length is OK */ - name_copy[TIPC_MAX_LINK_NAME -1 ] =0 ; -/* need above in case non-Posix strncpy() doesn't pad with nulls */ -strncpy (name_copy, name,TIPC_MAX_LINK_NAME ); -if (name_copy[TIPC_MAX_LINK_NAME -1 ] !=0 ) -return 0 ; - -/* ensure all component parts of link name are present */ - addr_local = name_copy; - if_local =strchr (addr_local,':' ); -if (if_local ==NULL ) -return 0 ; - *(if_local++) =0 ; - addr_peer =strchr (if_local,'-' ); -if (addr_peer ==NULL ) -return 0 ; - *(addr_peer++) =0 ; - if_local_len = addr_peer - if_local; - if_peer =strchr (addr_peer,':' ); -if (if_peer ==NULL ) -return 0 ; - *(if_peer++) =0 ; - if_peer_len =strlen (if_peer) +1 ; - -/* validate component parts of link name */ -if ((sscanf (addr_local,"%u.%u.%u%c" , - &z_local, &c_local, &n_local, &dummy) !=3 ) || - (sscanf (addr_peer,"%u.%u.%u%c" , - &z_peer, &c_peer, &n_peer, &dummy) !=3 ) || - (z_local >255 ) || (c_local >4095 ) || (n_local >4095 ) || - (z_peer >255 ) || (c_peer >4095 ) || (n_peer >4095 ) || - (if_local_len <=1 ) || (if_local_len >TIPC_MAX_IF_NAME ) || - (if_peer_len <=1 ) || (if_peer_len >TIPC_MAX_IF_NAME )) -return 0 ; - -/* return link name components, if necessary */ -if (name_parts) { - name_parts->addr_local =tipc_addr (z_local, c_local, n_local); -strcpy (name_parts->if_local, if_local); - name_parts->addr_peer =tipc_addr (z_peer, c_peer, n_peer); -strcpy (name_parts->if_peer, if_peer); - } -return 1 ; -} - -/** * link_timeout - handle expiration of link timer * @l_ptr: pointer to link *
@@ -2580,25 +2500,21 @@ void tipc_link_set_queue_limits(struct tipc_link *l_ptr, u32 window)static struct tipc_link *link_find_link (const char *name,struct tipc_node **node) { -struct tipc_link_name link_name_parts; -struct tipc_bearer *b_ptr;struct tipc_link *l_ptr; +struct tipc_node *n_ptr; +int i; -if (!link_name_validate (name, &link_name_parts)) -return NULL ; - - b_ptr =tipc_bearer_find_interface (link_name_parts.if_local); -if (!b_ptr) -return NULL ; - - *node =tipc_node_find (link_name_parts.addr_peer); -if (!*node) -return NULL ; - - l_ptr = (*node)->links[b_ptr->identity]; -if (!l_ptr ||strcmp (l_ptr->name, name)) -return NULL ; - +list_for_each_entry (n_ptr, &tipc_node_list, list) { +for (i =0 ; i <MAX_BEARERS ; i++) { + l_ptr = n_ptr->links[i]; +if (l_ptr && !strcmp (l_ptr->name, name)) + goto found; + } + } + l_ptr =NULL ; + n_ptr =NULL ; +found: + *node = n_ptr;return l_ptr; }
Signature · 1 line
1.7.9.5
David Miller
maintainerFrom: Jon Maloy <[email protected]>
Date: Fri, 18 Oct 2013 07:23:13 +0200
Review
Quoted 8 lines
Some small and relatively straightforward patches. With exception of the two first ones they are all unrelated and address minor issues.
v2: update of v1 (http://patchwork.ozlabs.org/patch/277404/)
(quoted diff) +0
-3-added commit to use memcpy_fromiovec on user data as per v1 feedback -updated sparse fix commit to drop chunks covered by above commit -added new commit that greatly simplifies the link lookup routine
Series applied, thanks Jon.