From 7d2b250cbcaa6bbca2c7ad48757c73d4f1ace585 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 29 Oct 2018 12:20:44 -0600 Subject: [PATCH] net/netdev: All utility functions that lookup network devices should begin with netdev_findby_. Also correct some comments and the name of a formal parameter. --- net/arp/arp_send.c | 2 +- net/icmp/icmp_sendto.c | 2 +- net/icmpv6/icmpv6_neighbor.c | 2 +- net/icmpv6/icmpv6_sendto.c | 2 +- net/inet/ipv4_getsockname.c | 2 +- net/inet/ipv6_getsockname.c | 2 +- net/ipforward/ipv4_forward.c | 2 +- net/ipforward/ipv6_forward.c | 2 +- net/netdev/netdev.h | 32 ++++++++++++------------ net/netdev/netdev_findbyaddr.c | 41 +++++++++++++++---------------- net/netdev/netdev_ioctl.c | 2 +- net/netdev/netdev_txnotify.c | 4 +-- net/sixlowpan/sixlowpan_tcpsend.c | 2 +- net/sixlowpan/sixlowpan_udpsend.c | 4 +-- net/tcp/tcp_finddev.c | 4 +-- net/udp/udp_finddev.c | 24 +++++++++--------- 16 files changed, 64 insertions(+), 65 deletions(-) diff --git a/net/arp/arp_send.c b/net/arp/arp_send.c index 6c745bd952..70bf12f752 100644 --- a/net/arp/arp_send.c +++ b/net/arp/arp_send.c @@ -223,7 +223,7 @@ int arp_send(in_addr_t ipaddr) /* Get the device that can route this request */ - dev = netdev_findby_ipv4addr(INADDR_ANY, ipaddr); + dev = netdev_findby_ripv4addr(INADDR_ANY, ipaddr); if (!dev) { nerr("ERROR: Unreachable: %08lx\n", (unsigned long)ipaddr); diff --git a/net/icmp/icmp_sendto.c b/net/icmp/icmp_sendto.c index cdff2851ed..c384d1efdd 100644 --- a/net/icmp/icmp_sendto.c +++ b/net/icmp/icmp_sendto.c @@ -397,7 +397,7 @@ ssize_t icmp_sendto(FAR struct socket *psock, FAR const void *buf, size_t len, /* Get the device that will be used to route this ICMP ECHO request */ - dev = netdev_findby_ipv4addr(INADDR_ANY, inaddr->sin_addr.s_addr); + dev = netdev_findby_ripv4addr(INADDR_ANY, inaddr->sin_addr.s_addr); if (dev == NULL) { nerr("ERROR: Not reachable\n"); diff --git a/net/icmpv6/icmpv6_neighbor.c b/net/icmpv6/icmpv6_neighbor.c index 6245c22fe6..a071d11e91 100644 --- a/net/icmpv6/icmpv6_neighbor.c +++ b/net/icmpv6/icmpv6_neighbor.c @@ -222,7 +222,7 @@ int icmpv6_neighbor(const net_ipv6addr_t ipaddr) /* Get the device that can route this request */ - dev = netdev_findby_ipv6addr(g_ipv6_unspecaddr, ipaddr); + dev = netdev_findby_ripv6addr(g_ipv6_unspecaddr, ipaddr); if (!dev) { nerr("ERROR: Unreachable: %08lx\n", (unsigned long)ipaddr); diff --git a/net/icmpv6/icmpv6_sendto.c b/net/icmpv6/icmpv6_sendto.c index 4d522851ca..8c13ba196d 100644 --- a/net/icmpv6/icmpv6_sendto.c +++ b/net/icmpv6/icmpv6_sendto.c @@ -389,7 +389,7 @@ ssize_t icmpv6_sendto(FAR struct socket *psock, FAR const void *buf, size_t len, /* Get the device that will be used to route this ICMPv6 ECHO request */ - dev = netdev_findby_ipv6addr(g_ipv6_unspecaddr, + dev = netdev_findby_ripv6addr(g_ipv6_unspecaddr, inaddr->sin6_addr.s6_addr16); if (dev == NULL) { diff --git a/net/inet/ipv4_getsockname.c b/net/inet/ipv4_getsockname.c index cfcbd3dcb9..149f6e1263 100644 --- a/net/inet/ipv4_getsockname.c +++ b/net/inet/ipv4_getsockname.c @@ -154,7 +154,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr, ripaddr = lipaddr; } - dev = netdev_findby_ipv4addr(lipaddr, ripaddr); + dev = netdev_findby_ripv4addr(lipaddr, ripaddr); if (dev == NULL) { diff --git a/net/inet/ipv6_getsockname.c b/net/inet/ipv6_getsockname.c index 8de7c5b7d3..05e8fb9c2e 100644 --- a/net/inet/ipv6_getsockname.c +++ b/net/inet/ipv6_getsockname.c @@ -155,7 +155,7 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr, ripaddr = lipaddr; } - dev = netdev_findby_ipv6addr(*lipaddr, *ripaddr); + dev = netdev_findby_ripv6addr(*lipaddr, *ripaddr); if (!dev) { net_unlock(); diff --git a/net/ipforward/ipv4_forward.c b/net/ipforward/ipv4_forward.c index a04777f4cb..a6ae056642 100644 --- a/net/ipforward/ipv4_forward.c +++ b/net/ipforward/ipv4_forward.c @@ -436,7 +436,7 @@ int ipv4_forward(FAR struct net_driver_s *dev, FAR struct ipv4_hdr_s *ipv4) destipaddr = net_ip4addr_conv32(ipv4->destipaddr); srcipaddr = net_ip4addr_conv32(ipv4->srcipaddr); - fwddev = netdev_findby_ipv4addr(srcipaddr, destipaddr); + fwddev = netdev_findby_ripv4addr(srcipaddr, destipaddr); if (fwddev == NULL) { nwarn("WARNING: Not routable\n"); diff --git a/net/ipforward/ipv6_forward.c b/net/ipforward/ipv6_forward.c index 6f5c8ac198..673158f3cf 100644 --- a/net/ipforward/ipv6_forward.c +++ b/net/ipforward/ipv6_forward.c @@ -573,7 +573,7 @@ int ipv6_forward(FAR struct net_driver_s *dev, FAR struct ipv6_hdr_s *ipv6) /* Search for a device that can forward this packet. */ - fwddev = netdev_findby_ipv6addr(ipv6->srcipaddr, ipv6->destipaddr); + fwddev = netdev_findby_ripv6addr(ipv6->srcipaddr, ipv6->destipaddr); if (fwddev == NULL) { nwarn("WARNING: Not routable\n"); diff --git a/net/netdev/netdev.h b/net/netdev/netdev.h index 4c6d51e290..210bd4f40d 100644 --- a/net/netdev/netdev.h +++ b/net/netdev/netdev.h @@ -1,7 +1,7 @@ /**************************************************************************** * net/netdev/netdev.h * - * Copyright (C) 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2014-2015, 2018 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -178,8 +178,10 @@ FAR struct net_driver_s *netdev_findbyname(FAR const char *ifname); int netdev_foreach(netdev_callback_t callback, FAR void *arg); +#if CONFIG_NSOCKET_DESCRIPTORS > 0 + /**************************************************************************** - * Name: netdev_finddevice_ipv4addr + * Name: netdev_findby_lipv4addr * * Description: * Find a previously registered network device by matching a local address @@ -187,7 +189,7 @@ int netdev_foreach(netdev_callback_t callback, FAR void *arg); * (since a "down" device has no meaningful address). * * Input Parameters: - * ripaddr - Remote address of a connection to use in the lookup + * lipaddr - Local, IPv4 address of assigned to the device * * Returned Value: * Pointer to driver on success; null on failure @@ -195,11 +197,11 @@ int netdev_foreach(netdev_callback_t callback, FAR void *arg); ****************************************************************************/ #ifdef CONFIG_NET_IPv4 -FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr); +FAR struct net_driver_s *netdev_findby_lipv4addr(in_addr_t lipaddr); #endif /**************************************************************************** - * Name: netdev_finddevice_ipv6addr + * Name: netdev_findby_lipv6addr * * Description: * Find a previously registered network device by matching a local address @@ -207,7 +209,7 @@ FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr); * (since a "down" device has no meaningful address). * * Input Parameters: - * ripaddr - Remote address of a connection to use in the lookup + * lipaddr - Local, IPv6 address of assigned to the device * * Returned Value: * Pointer to driver on success; null on failure @@ -215,12 +217,11 @@ FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr); ****************************************************************************/ #ifdef CONFIG_NET_IPv6 -FAR struct net_driver_s * -netdev_finddevice_ipv6addr(const net_ipv6addr_t ripaddr); +FAR struct net_driver_s *netdev_findby_lipv6addr(const net_ipv6addr_t lipaddr); #endif /**************************************************************************** - * Name: netdev_findby_ipv4addr + * Name: netdev_findby_ripv4addr * * Description: * Find a previously registered network device by matching the remote @@ -235,14 +236,13 @@ netdev_finddevice_ipv6addr(const net_ipv6addr_t ripaddr); * ****************************************************************************/ -#if CONFIG_NSOCKET_DESCRIPTORS > 0 #ifdef CONFIG_NET_IPv4 -FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t lipaddr, - in_addr_t ripaddr); +FAR struct net_driver_s *netdev_findby_ripv4addr(in_addr_t lipaddr, + in_addr_t ripaddr); #endif /**************************************************************************** - * Name: netdev_findby_ipv6addr + * Name: netdev_findby_ripv6addr * * Description: * Find a previously registered network device by matching the remote @@ -258,10 +258,10 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t lipaddr, ****************************************************************************/ #ifdef CONFIG_NET_IPv6 -FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t lipaddr, - const net_ipv6addr_t ripaddr); -#endif +FAR struct net_driver_s *netdev_findby_ripv6addr(const net_ipv6addr_t lipaddr, + const net_ipv6addr_t ripaddr); #endif +#endif /* CONFIG_NSOCKET_DESCRIPTORS > 0 */ /**************************************************************************** * Name: netdev_findbyindex diff --git a/net/netdev/netdev_findbyaddr.c b/net/netdev/netdev_findbyaddr.c index f887ba2176..0500a2b3a7 100644 --- a/net/netdev/netdev_findbyaddr.c +++ b/net/netdev/netdev_findbyaddr.c @@ -62,7 +62,7 @@ ****************************************************************************/ /**************************************************************************** - * Name: netdev_finddevice_ipv4addr + * Name: netdev_findby_lipv4addr * * Description: * Find a previously registered network device by matching a local address @@ -70,7 +70,7 @@ * (since a "down" device has no meaningful address). * * Input Parameters: - * ripaddr - Remote address of a connection to use in the lookup + * lipaddr - Local, IPv4 address of assigned to the device * * Returned Value: * Pointer to driver on success; null on failure @@ -78,7 +78,7 @@ ****************************************************************************/ #ifdef CONFIG_NET_IPv4 -FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr) +FAR struct net_driver_s *netdev_findby_lipv4addr(in_addr_t lipaddr) { FAR struct net_driver_s *dev; @@ -93,7 +93,7 @@ FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr) { /* Yes.. check for an address match (under the netmask) */ - if (net_ipv4addr_maskcmp(dev->d_ipaddr, ripaddr, + if (net_ipv4addr_maskcmp(dev->d_ipaddr, lipaddr, dev->d_netmask)) { /* Its a match */ @@ -112,7 +112,7 @@ FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr) #endif /* CONFIG_NET_IPv4 */ /**************************************************************************** - * Name: netdev_finddevice_ipv6addr + * Name: netdev_findby_lipv6addr * * Description: * Find a previously registered network device by matching a local address @@ -120,7 +120,7 @@ FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr) * (since a "down" device has no meaningful address). * * Input Parameters: - * ripaddr - Remote address of a connection to use in the lookup + * lipaddr - Local, IPv6 address of assigned to the device * * Returned Value: * Pointer to driver on success; null on failure @@ -128,8 +128,7 @@ FAR struct net_driver_s *netdev_finddevice_ipv4addr(in_addr_t ripaddr) ****************************************************************************/ #ifdef CONFIG_NET_IPv6 -FAR struct net_driver_s * -netdev_finddevice_ipv6addr(const net_ipv6addr_t ripaddr) +FAR struct net_driver_s *netdev_findby_lipv6addr(const net_ipv6addr_t lipaddr) { FAR struct net_driver_s *dev; @@ -144,7 +143,7 @@ netdev_finddevice_ipv6addr(const net_ipv6addr_t ripaddr) { /* Yes.. check for an address match (under the netmask) */ - if (net_ipv6addr_maskcmp(dev->d_ipv6addr, ripaddr, + if (net_ipv6addr_maskcmp(dev->d_ipv6addr, lipaddr, dev->d_ipv6netmask)) { /* Its a match */ @@ -163,7 +162,7 @@ netdev_finddevice_ipv6addr(const net_ipv6addr_t ripaddr) #endif /* CONFIG_NET_IPv6 */ /**************************************************************************** - * Name: netdev_findby_ipv4addr + * Name: netdev_findby_ripv4addr * * Description: * Find a previously registered network device by matching the remote @@ -179,8 +178,8 @@ netdev_finddevice_ipv6addr(const net_ipv6addr_t ripaddr) ****************************************************************************/ #ifdef CONFIG_NET_IPv4 -FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t lipaddr, - in_addr_t ripaddr) +FAR struct net_driver_s *netdev_findby_ripv4addr(in_addr_t lipaddr, + in_addr_t ripaddr) { struct net_driver_s *dev; #ifdef CONFIG_NET_ROUTE @@ -208,13 +207,13 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t lipaddr, { /* Return the device associated with the local address */ - return netdev_finddevice_ipv4addr(lipaddr); + return netdev_findby_lipv4addr(lipaddr); } } /* Check if the address maps to a locally available network */ - dev = netdev_finddevice_ipv4addr(ripaddr); + dev = netdev_findby_lipv4addr(ripaddr); if (dev) { return dev; @@ -234,7 +233,7 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t lipaddr, * router address */ - dev = netdev_finddevice_ipv4addr(router); + dev = netdev_findby_lipv4addr(router); if (dev) { return dev; @@ -252,7 +251,7 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t lipaddr, #endif /* CONFIG_NET_IPv4 */ /**************************************************************************** - * Name: netdev_findby_ipv6addr + * Name: netdev_findby_ripv6addr * * Description: * Find a previously registered network device by matching the remote @@ -268,8 +267,8 @@ FAR struct net_driver_s *netdev_findby_ipv4addr(in_addr_t lipaddr, ****************************************************************************/ #ifdef CONFIG_NET_IPv6 -FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t lipaddr, - const net_ipv6addr_t ripaddr) +FAR struct net_driver_s *netdev_findby_ripv6addr(const net_ipv6addr_t lipaddr, + const net_ipv6addr_t ripaddr) { struct net_driver_s *dev; #ifdef CONFIG_NET_ROUTE @@ -299,13 +298,13 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t lipaddr, { /* Return the device associated with the local address */ - return netdev_finddevice_ipv6addr(lipaddr); + return netdev_findby_lipv6addr(lipaddr); } } /* Check if the address maps to a locally available network */ - dev = netdev_finddevice_ipv6addr(ripaddr); + dev = netdev_findby_lipv6addr(ripaddr); if (dev) { return dev; @@ -325,7 +324,7 @@ FAR struct net_driver_s *netdev_findby_ipv6addr(const net_ipv6addr_t lipaddr, * router address */ - dev = netdev_finddevice_ipv6addr(router); + dev = netdev_findby_lipv6addr(router); if (dev) { return dev; diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index cff7f58177..36efe4b6b8 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -1134,7 +1134,7 @@ static FAR struct net_driver_s *netdev_imsfdev(FAR struct ip_msfilter *imsf) * of the local device. */ - return netdev_finddevice_ipv4addr(imsf->imsf_interface.s_addr); + return netdev_findby_lipv4addr(imsf->imsf_interface.s_addr); } #endif diff --git a/net/netdev/netdev_txnotify.c b/net/netdev/netdev_txnotify.c index d2b2e5e570..66a1495f22 100644 --- a/net/netdev/netdev_txnotify.c +++ b/net/netdev/netdev_txnotify.c @@ -77,7 +77,7 @@ void netdev_ipv4_txnotify(in_addr_t lipaddr, in_addr_t ripaddr) /* Find the device driver that serves the subnet of the remote address */ - dev = netdev_findby_ipv4addr(lipaddr, ripaddr); + dev = netdev_findby_ripv4addr(lipaddr, ripaddr); if (dev && dev->d_txavail) { /* Notify the device driver that new TX data is available. */ @@ -112,7 +112,7 @@ void netdev_ipv6_txnotify(FAR const net_ipv6addr_t lipaddr, /* Find the device driver that serves the subnet of the remote address */ - dev = netdev_findby_ipv6addr(lipaddr, ripaddr); + dev = netdev_findby_ripv6addr(lipaddr, ripaddr); if (dev && dev->d_txavail) { /* Notify the device driver that new TX data is available. */ diff --git a/net/sixlowpan/sixlowpan_tcpsend.c b/net/sixlowpan/sixlowpan_tcpsend.c index 27ab8aeb28..db64c2265f 100644 --- a/net/sixlowpan/sixlowpan_tcpsend.c +++ b/net/sixlowpan/sixlowpan_tcpsend.c @@ -813,7 +813,7 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf, /* Route outgoing message to the correct device */ - dev = netdev_findby_ipv6addr(conn->u.ipv6.laddr, conn->u.ipv6.raddr); + dev = netdev_findby_ripv6addr(conn->u.ipv6.laddr, conn->u.ipv6.raddr); if (dev == NULL) { nwarn("WARNING: Not routable\n"); diff --git a/net/sixlowpan/sixlowpan_udpsend.c b/net/sixlowpan/sixlowpan_udpsend.c index 0f73170176..bede2da378 100644 --- a/net/sixlowpan/sixlowpan_udpsend.c +++ b/net/sixlowpan/sixlowpan_udpsend.c @@ -206,8 +206,8 @@ ssize_t psock_6lowpan_udp_sendto(FAR struct socket *psock, /* Route outgoing message to the correct device */ - dev = netdev_findby_ipv6addr(conn->u.ipv6.laddr, - to6->sin6_addr.in6_u.u6_addr16); + dev = netdev_findby_ripv6addr(conn->u.ipv6.laddr, + to6->sin6_addr.in6_u.u6_addr16); if (dev == NULL) { nwarn("WARNING: Not routable\n"); diff --git a/net/tcp/tcp_finddev.c b/net/tcp/tcp_finddev.c index feccc8400b..ed4cfc9757 100644 --- a/net/tcp/tcp_finddev.c +++ b/net/tcp/tcp_finddev.c @@ -95,7 +95,7 @@ static int tcp_find_ipv4_device(FAR struct tcp_conn_s *conn, in_addr_t addr) * based on the provided IP address. */ - conn->dev = netdev_findby_ipv4addr(addr, addr); + conn->dev = netdev_findby_ripv4addr(addr, addr); /* Return success if we found the device */ @@ -145,7 +145,7 @@ static int tcp_find_ipv6_device(FAR struct tcp_conn_s *conn, * based on the provided IP address. */ - conn->dev = netdev_findby_ipv6addr(addr, addr); + conn->dev = netdev_findby_ripv6addr(addr, addr); /* Return success if we found the device */ diff --git a/net/udp/udp_finddev.c b/net/udp/udp_finddev.c index 5ebaad4206..442b1decea 100644 --- a/net/udp/udp_finddev.c +++ b/net/udp/udp_finddev.c @@ -154,8 +154,8 @@ FAR struct net_driver_s *udp_find_laddr_device(FAR struct udp_conn_s *conn) } else { - return netdev_findby_ipv4addr(conn->u.ipv4.laddr, - conn->u.ipv4.laddr); + return netdev_findby_ripv4addr(conn->u.ipv4.laddr, + conn->u.ipv4.laddr); } } #endif @@ -177,8 +177,8 @@ FAR struct net_driver_s *udp_find_laddr_device(FAR struct udp_conn_s *conn) } else { - return netdev_findby_ipv6addr(conn->u.ipv6.laddr, - conn->u.ipv6.laddr); + return netdev_findby_ripv6addr(conn->u.ipv6.laddr, + conn->u.ipv6.laddr); } } #endif @@ -234,8 +234,8 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn) } else { - return netdev_findby_ipv4addr(conn->u.ipv4.laddr, - conn->u.ipv4.laddr); + return netdev_findby_ripv4addr(conn->u.ipv4.laddr, + conn->u.ipv4.laddr); } } @@ -247,8 +247,8 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn) { /* Normal lookup using the verified remote address */ - return netdev_findby_ipv4addr(conn->u.ipv4.laddr, - conn->u.ipv4.raddr); + return netdev_findby_ripv4addr(conn->u.ipv4.laddr, + conn->u.ipv4.raddr); } else { @@ -286,8 +286,8 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn) } else { - return netdev_findby_ipv6addr(conn->u.ipv6.laddr, - conn->u.ipv6.laddr); + return netdev_findby_ripv6addr(conn->u.ipv6.laddr, + conn->u.ipv6.laddr); } } @@ -299,8 +299,8 @@ FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn) { /* Normal lookup using the verified remote address */ - return netdev_findby_ipv6addr(conn->u.ipv6.laddr, - conn->u.ipv6.raddr); + return netdev_findby_ripv6addr(conn->u.ipv6.laddr, + conn->u.ipv6.raddr); } else {