git: 531ef35241b5 - main - cxgbe/iw_cxgbe: Always set a vnet around calls to IN_LOOPBACK.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sun, 02 Apr 2023 01:09:55 UTC
The branch main has been updated by np: URL: https://cgit.FreeBSD.org/src/commit/?id=531ef35241b5b5934f8cd78ca628c21cb0494d88 commit 531ef35241b5b5934f8cd78ca628c21cb0494d88 Author: Navdeep Parhar <np@FreeBSD.org> AuthorDate: 2022-10-13 22:34:56 +0000 Commit: Navdeep Parhar <np@FreeBSD.org> CommitDate: 2023-04-01 23:19:10 +0000 cxgbe/iw_cxgbe: Always set a vnet around calls to IN_LOOPBACK. This is catch up with efe58855f3ea. MFC after: 1 week Sponsored by: Chelsio Communications --- sys/dev/cxgbe/iw_cxgbe/cm.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/sys/dev/cxgbe/iw_cxgbe/cm.c b/sys/dev/cxgbe/iw_cxgbe/cm.c index 457290875583..045da316a0a0 100644 --- a/sys/dev/cxgbe/iw_cxgbe/cm.c +++ b/sys/dev/cxgbe/iw_cxgbe/cm.c @@ -933,7 +933,7 @@ err: return; } -static inline int c4iw_zero_addr(struct sockaddr *addr) +static inline bool c4iw_zero_addr(struct sockaddr *addr) { struct in6_addr *ip6; @@ -946,19 +946,29 @@ static inline int c4iw_zero_addr(struct sockaddr *addr) } } -static inline int c4iw_loopback_addr(struct sockaddr *addr) +#define _IN_LOOPBACK(i) (((in_addr_t)(i) & 0xff000000) == 0x7f000000) +static inline bool c4iw_loopback_addr(struct sockaddr *addr, struct vnet *vnet) { - if (addr->sa_family == AF_INET) - return IN_LOOPBACK( - ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr)); - else - return IN6_IS_ADDR_LOOPBACK( - &((struct sockaddr_in6 *) addr)->sin6_addr); + bool ret; + + if (addr->sa_family == AF_INET) { + if (vnet == NULL) + ret = _IN_LOOPBACK(ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr)); + else { + CURVNET_SET_QUIET(vnet); + ret = IN_LOOPBACK(ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr)); + CURVNET_RESTORE(); + } + } else { + ret = IN6_IS_ADDR_LOOPBACK(&((struct sockaddr_in6 *) addr)->sin6_addr); + } + return (ret); } +#undef _IN_LOOPBACK -static inline int c4iw_any_addr(struct sockaddr *addr) +static inline bool c4iw_any_addr(struct sockaddr *addr, struct vnet *vnet) { - return c4iw_zero_addr(addr) || c4iw_loopback_addr(addr); + return c4iw_zero_addr(addr) || c4iw_loopback_addr(addr, vnet); } static void @@ -971,7 +981,8 @@ process_newconn(struct c4iw_listen_ep *master_lep, struct socket *new_so) MPASS(new_so != NULL); - if (c4iw_any_addr((struct sockaddr *)&master_lep->com.local_addr)) { + if (c4iw_any_addr((struct sockaddr *)&master_lep->com.local_addr, + new_so->so_vnet)) { /* Here we need to find the 'real_lep' that belongs to the * incomming socket's network interface, such that the newly * created 'ep' can be attached to the real 'lep'. @@ -2734,7 +2745,7 @@ c4iw_create_listen(struct iw_cm_id *cm_id, int backlog) * invoke solisten() as first listener callback has already created * listeners for all other devices(via solisten). */ - if (c4iw_any_addr((struct sockaddr *)&lep->com.local_addr)) { + if (c4iw_any_addr((struct sockaddr *)&lep->com.local_addr, NULL)) { port_info = add_ep_to_listenlist(lep); /* skip solisten() if refcnt > 1, as the listeners were * already created by 'Master lep' @@ -2788,7 +2799,8 @@ c4iw_destroy_listen(struct iw_cm_id *cm_id) states[lep->com.state]); lep->com.state = DEAD; - if (c4iw_any_addr((struct sockaddr *)&lep->com.local_addr)) { + if (c4iw_any_addr((struct sockaddr *)&lep->com.local_addr, + lep->com.so->so_vnet)) { /* if no refcount then close listen socket */ if (!rem_ep_from_listenlist(lep)) close_socket(lep->com.so);