Re: [tipc-discussion] [PATCH net-next] tipc: Use is_broadcast_ether_addr() instead of memcmp()
From: Huang Guobin Date: Sun, 2 Aug 2020 22:00:55 -0400 > Using is_broadcast_ether_addr() instead of directly use > memcmp() to determine if the ethernet address is broadcast > address. > > spatch with a semantic match is used to found this problem. > (http://coccinelle.lip6.fr/) > > Signed-off-by: Huang Guobin Applied, thank you. ___ tipc-discussion mailing list tipc-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tipc-discussion
[tipc-discussion] [PATCH net 1/2] ipv6: add ipv6_dev_find()
This is to add an ip_dev_find like function for ipv6, used to find the dev by saddr. It will be used by TIPC protocol. So also export it. Signed-off-by: Xin Long --- include/net/addrconf.h | 2 ++ net/ipv6/addrconf.c| 39 +++ 2 files changed, 41 insertions(+) diff --git a/include/net/addrconf.h b/include/net/addrconf.h index 8418b7d..ba3f6c15 100644 --- a/include/net/addrconf.h +++ b/include/net/addrconf.h @@ -97,6 +97,8 @@ bool ipv6_chk_custom_prefix(const struct in6_addr *addr, int ipv6_chk_prefix(const struct in6_addr *addr, struct net_device *dev); +struct net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr); + struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr, struct net_device *dev, int strict); diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c index 840bfdb..857d6f9 100644 --- a/net/ipv6/addrconf.c +++ b/net/ipv6/addrconf.c @@ -1983,6 +1983,45 @@ int ipv6_chk_prefix(const struct in6_addr *addr, struct net_device *dev) } EXPORT_SYMBOL(ipv6_chk_prefix); +/** + * ipv6_dev_find - find the first device with a given source address. + * @net: the net namespace + * @addr: the source address + * + * The caller should be protected by RCU, or RTNL. + */ +struct net_device *ipv6_dev_find(struct net *net, const struct in6_addr *addr) +{ + unsigned int hash = inet6_addr_hash(net, addr); + struct inet6_ifaddr *ifp, *result = NULL; + struct net_device *dev = NULL; + + rcu_read_lock(); + hlist_for_each_entry_rcu(ifp, _addr_lst[hash], addr_lst) { + if (net_eq(dev_net(ifp->idev->dev), net) && + ipv6_addr_equal(>addr, addr)) { + result = ifp; + break; + } + } + + if (!result) { + struct rt6_info *rt; + + rt = rt6_lookup(net, addr, NULL, 0, NULL, 0); + if (rt) { + dev = rt->dst.dev; + ip6_rt_put(rt); + } + } else { + dev = result->idev->dev; + } + rcu_read_unlock(); + + return dev; +} +EXPORT_SYMBOL(ipv6_dev_find); + struct inet6_ifaddr *ipv6_get_ifaddr(struct net *net, const struct in6_addr *addr, struct net_device *dev, int strict) { -- 2.1.0 ___ tipc-discussion mailing list tipc-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tipc-discussion
[tipc-discussion] [PATCH net 2/2] tipc: set ub->ifindex for local ipv6 address
Without ub->ifindex set for ipv6 address in tipc_udp_enable(), ipv6_sock_mc_join() may make the wrong dev join the multicast address in enable_mcast(). This causes that tipc links would never be created. So fix it by getting the right netdev and setting ub->ifindex, as it does for ipv4 address. Reported-by: Shuang Li Signed-off-by: Xin Long --- net/tipc/udp_media.c | 8 1 file changed, 8 insertions(+) diff --git a/net/tipc/udp_media.c b/net/tipc/udp_media.c index 28a283f..9dec596 100644 --- a/net/tipc/udp_media.c +++ b/net/tipc/udp_media.c @@ -738,6 +738,13 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, b->mtu = b->media->mtu; #if IS_ENABLED(CONFIG_IPV6) } else if (local.proto == htons(ETH_P_IPV6)) { + struct net_device *dev; + + dev = ipv6_dev_find(net, ); + if (!dev) { + err = -ENODEV; + goto err; + } udp_conf.family = AF_INET6; udp_conf.use_udp6_tx_checksums = true; udp_conf.use_udp6_rx_checksums = true; @@ -745,6 +752,7 @@ static int tipc_udp_enable(struct net *net, struct tipc_bearer *b, udp_conf.local_ip6 = in6addr_any; else udp_conf.local_ip6 = local.ipv6; + ub->ifindex = dev->ifindex; b->mtu = 1280; #endif } else { -- 2.1.0 ___ tipc-discussion mailing list tipc-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tipc-discussion
[tipc-discussion] [PATCH net 0/2] net: fix a mcast issue for tipc udp media
Patch 1 is to add a function to get the dev by source address, whcih will be used by Patch 2. Xin Long (2): ipv6: add ipv6_dev_find() tipc: set ub->ifindex for local ipv6 address include/net/addrconf.h | 2 ++ net/ipv6/addrconf.c| 39 +++ net/tipc/udp_media.c | 8 3 files changed, 49 insertions(+) -- 2.1.0 ___ tipc-discussion mailing list tipc-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tipc-discussion
Re: [tipc-discussion] [PATCH net-next] tipc: Use is_broadcast_ether_addr() instead of memcmp()
On 8/3/20 10:00 AM, Huang Guobin wrote: > Using is_broadcast_ether_addr() instead of directly use > memcmp() to determine if the ethernet address is broadcast > address. > > spatch with a semantic match is used to found this problem. > (http://coccinelle.lip6.fr/) > > Signed-off-by: Huang Guobin Acked-by: Ying Xue > --- > net/tipc/eth_media.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/net/tipc/eth_media.c b/net/tipc/eth_media.c > index 8b0bb600602d..c68019697cfe 100644 > --- a/net/tipc/eth_media.c > +++ b/net/tipc/eth_media.c > @@ -62,12 +62,10 @@ static int tipc_eth_raw2addr(struct tipc_bearer *b, >struct tipc_media_addr *addr, >char *msg) > { > - char bcast_mac[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; > - > memset(addr, 0, sizeof(*addr)); > ether_addr_copy(addr->value, msg); > addr->media_id = TIPC_MEDIA_TYPE_ETH; > - addr->broadcast = !memcmp(addr->value, bcast_mac, ETH_ALEN); > + addr->broadcast = is_broadcast_ether_addr(addr->value); > return 0; > } > > ___ tipc-discussion mailing list tipc-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/tipc-discussion