From patchwork Fri Aug 26 08:52:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Alpe X-Patchwork-Id: 663014 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3sLFHJ1yX6z9sBf for ; Fri, 26 Aug 2016 18:55:08 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751014AbcHZIy5 (ORCPT ); Fri, 26 Aug 2016 04:54:57 -0400 Received: from sesbmg23.ericsson.net ([193.180.251.37]:54949 "EHLO sesbmg23.ericsson.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751387AbcHZIyp (ORCPT ); Fri, 26 Aug 2016 04:54:45 -0400 X-AuditID: c1b4fb25-8bfff70000001071-80-57c0037e01bd Received: from ESESSHC011.ericsson.se (Unknown_Domain [153.88.183.51]) by (Symantec Mail Security) with SMTP id 3A.8E.04209.E7300C75; Fri, 26 Aug 2016 10:53:18 +0200 (CEST) Received: from tipsy.lab.linux.ericsson.se (10.35.28.120) by ESESSHC011.ericsson.se (153.88.183.51) with Microsoft SMTP Server (TLS) id 14.3.301.0; Fri, 26 Aug 2016 10:53:17 +0200 From: Richard Alpe To: CC: , Richard Alpe Subject: [PATCH net-next 6/7] tipc: add the ability to get UDP options via netlink Date: Fri, 26 Aug 2016 10:52:55 +0200 Message-ID: <1472201576-26588-7-git-send-email-richard.alpe@ericsson.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1472201576-26588-1-git-send-email-richard.alpe@ericsson.com> References: <1472201576-26588-1-git-send-email-richard.alpe@ericsson.com> MIME-Version: 1.0 X-Originating-IP: [10.35.28.120] X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrCLMWRmVeSWpSXmKPExsUyM2K7sW4d84Fwg4OfRSyOLRCz2HI+y4HJ Y/eCz0wenzfJBTBFcdmkpOZklqUW6dslcGWsmrGNpWClUsWxu4eYGxg3ynQxcnJICJhIfHg3 h72LkYtDSGA9o8Tar7vYQBJCAtsZJda/LAKx2QT0JPYuO8YMYosIyEgc7V8AVsMsEC5xeMd7 1i5GDg5hgSCJ/pUFIGEWAVWJN+dWg5XwCnhKTHx1lRlil5zE+eM/wWxOAS+JnlNb2SFWeUos aznMAlEvKHFy5hMWiPESEgdfvGCGqFGTaL3xCmqOgsS3md1MExgFZiFpmYWkZQEj0ypG0eLU 4qTcdCNjvdSizOTi4vw8vbzUkk2MwLA7uOW36g7Gy28cDzEKcDAq8fAqGO0PF2JNLCuuzD3E KMHBrCTCG/IPKMSbklhZlVqUH19UmpNafIhRmoNFSZzX/6ViuJBAemJJanZqakFqEUyWiYNT qoExr/n/zuCFm9/Yrvl24Bu/yoGnwpMLJvGJTixQEjf6dmp58OS4iAXPJfLFIhO1akvv/uS9 qniWw1pxTYpxSrLwE5HsOxuyjZx+i9RMPb3D9nPNzJqf7edP8N+XM2BxT9leMqV7Wt2/PaL/ 3v1/9z389ykO32k/jj5SCXrpbhSSK3FWnKnyfr+SEktxRqKhFnNRcSIA6NA2LzcCAAA= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add UDP bearer options to netlink bearer get message. This is used by the tipc user space tool to display UDP options. The UDP bearer information is passed using either a sockaddr_in or sockaddr_in6 structs. This means the user space receiver should intermediately store the retrieved data in a large enough struct (sockaddr_strage) before casting to the proper IP version type. Signed-off-by: Richard Alpe Reviewed-by: Jon Maloy Acked-by: Ying Xue --- include/uapi/linux/tipc_netlink.h | 2 ++ net/tipc/bearer.c | 8 +++++ net/tipc/udp_media.c | 61 +++++++++++++++++++++++++++++++++++++++ net/tipc/udp_media.h | 1 + 4 files changed, 72 insertions(+) diff --git a/include/uapi/linux/tipc_netlink.h b/include/uapi/linux/tipc_netlink.h index b15664c..f9edd20 100644 --- a/include/uapi/linux/tipc_netlink.h +++ b/include/uapi/linux/tipc_netlink.h @@ -61,6 +61,7 @@ enum { TIPC_NL_MON_PEER_GET, TIPC_NL_PEER_REMOVE, TIPC_NL_BEARER_ADD, + TIPC_NL_UDP_GET_REMOTEIP, __TIPC_NL_CMD_MAX, TIPC_NL_CMD_MAX = __TIPC_NL_CMD_MAX - 1 @@ -100,6 +101,7 @@ enum { TIPC_NLA_UDP_UNSPEC, TIPC_NLA_UDP_LOCAL, /* sockaddr_storage */ TIPC_NLA_UDP_REMOTE, /* sockaddr_storage */ + TIPC_NLA_UDP_MULTI_REMOTEIP, /* flag */ __TIPC_NLA_UDP_MAX, TIPC_NLA_UDP_MAX = __TIPC_NLA_UDP_MAX - 1 diff --git a/net/tipc/bearer.c b/net/tipc/bearer.c index d7b442d..975dbeb 100644 --- a/net/tipc/bearer.c +++ b/net/tipc/bearer.c @@ -712,6 +712,14 @@ static int __tipc_nl_add_bearer(struct tipc_nl_msg *msg, goto prop_msg_full; nla_nest_end(msg->skb, prop); + +#ifdef CONFIG_TIPC_MEDIA_UDP + if (bearer->media->type_id == TIPC_MEDIA_TYPE_UDP) { + if (tipc_udp_nl_add_bearer_data(msg, bearer)) + goto attr_msg_full; + } +#endif + nla_nest_end(msg->skb, attrs); genlmsg_end(msg->skb, hdr); diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c index 6ece3c9..a6cdd98 100644 --- a/net/tipc/udp_media.c +++ b/net/tipc/udp_media.c @@ -401,6 +401,67 @@ static int enable_mcast(struct udp_bearer *ub, struct udp_media_addr *remote) return err; } +static int __tipc_nl_add_udp_addr(struct sk_buff *skb, + struct udp_media_addr *addr, int nla_t) +{ + if (ntohs(addr->proto) == ETH_P_IP) { + struct sockaddr_in ip4; + + ip4.sin_family = AF_INET; + ip4.sin_port = addr->port; + ip4.sin_addr.s_addr = addr->ipv4.s_addr; + if (nla_put(skb, nla_t, sizeof(ip4), &ip4)) + return -EMSGSIZE; + +#if IS_ENABLED(CONFIG_IPV6) + } else if (ntohs(addr->proto) == ETH_P_IPV6) { + struct sockaddr_in6 ip6; + + ip6.sin6_family = AF_INET6; + ip6.sin6_port = addr->port; + memcpy(&ip6.sin6_addr, &addr->ipv6, sizeof(struct in6_addr)); + if (nla_put(skb, nla_t, sizeof(ip6), &ip6)) + return -EMSGSIZE; +#endif + } + + return 0; +} + +int tipc_udp_nl_add_bearer_data(struct tipc_nl_msg *msg, struct tipc_bearer *b) +{ + struct udp_media_addr *src = (struct udp_media_addr *)&b->addr.value; + struct udp_media_addr *dst; + struct udp_bearer *ub; + struct nlattr *nest; + + ub = rcu_dereference_rtnl(b->media_ptr); + if (!ub) + return -ENODEV; + + nest = nla_nest_start(msg->skb, TIPC_NLA_BEARER_UDP_OPTS); + if (!nest) + goto msg_full; + + if (__tipc_nl_add_udp_addr(msg->skb, src, TIPC_NLA_UDP_LOCAL)) + goto msg_full; + + dst = (struct udp_media_addr *)&b->bcast_addr.value; + if (__tipc_nl_add_udp_addr(msg->skb, dst, TIPC_NLA_UDP_REMOTE)) + goto msg_full; + + if (!list_empty(&ub->rcast.list)) { + if (nla_put_flag(msg->skb, TIPC_NLA_UDP_MULTI_REMOTEIP)) + goto msg_full; + } + + nla_nest_end(msg->skb, nest); + return 0; +msg_full: + nla_nest_cancel(msg->skb, nest); + return -EMSGSIZE; +} + /** * tipc_parse_udp_addr - build udp media address from netlink data * @nlattr: netlink attribute containing sockaddr storage aligned address diff --git a/net/tipc/udp_media.h b/net/tipc/udp_media.h index 4dcb548..c06326a 100644 --- a/net/tipc/udp_media.h +++ b/net/tipc/udp_media.h @@ -39,6 +39,7 @@ #define _TIPC_UDP_MEDIA_H int tipc_udp_nl_bearer_add(struct tipc_bearer *b, struct nlattr *attr); +int tipc_udp_nl_add_bearer_data(struct tipc_nl_msg *msg, struct tipc_bearer *b); #endif #endif