diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2019-08-26 15:23:02 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2019-08-26 15:23:02 +0000 |
commit | 8fa9a032ef791599a610fa1b1c35275ac7915130 (patch) | |
tree | b12c6c81052876929147d67df433ba42930cf6b2 /sys/dev/usb | |
parent | 87278828548a9c51eb72780065d1a5094299a854 (diff) |
Replace umb_ntop() with sockaddr_ntop() which does almost the same thing.
Also change the storage type for the DNS addresses to struct in_addr since
that is more convinient for userland. This includes some minor other cleanup.
OK gerhard@
Diffstat (limited to 'sys/dev/usb')
-rw-r--r-- | sys/dev/usb/if_umb.c | 60 | ||||
-rw-r--r-- | sys/dev/usb/if_umb.h | 4 |
2 files changed, 26 insertions, 38 deletions
diff --git a/sys/dev/usb/if_umb.c b/sys/dev/usb/if_umb.c index b4c507c5744..5717d4ab0a9 100644 --- a/sys/dev/usb/if_umb.c +++ b/sys/dev/usb/if_umb.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_umb.c,v 1.23 2019/06/26 09:36:06 claudio Exp $ */ +/* $OpenBSD: if_umb.c,v 1.24 2019/08/26 15:23:01 claudio Exp $ */ /* * Copyright (c) 2016 genua mbH @@ -187,8 +187,6 @@ void umb_decode_qmi(struct umb_softc *, uint8_t *, int); void umb_intr(struct usbd_xfer *, void *, usbd_status); -char *umb_ntop(struct sockaddr *); - int umb_xfer_tout = USBD_DEFAULT_TIMEOUT; uint8_t umb_uuid_basic_connect[] = MBIM_UUID_BASIC_CONNECT; @@ -907,7 +905,7 @@ umb_statechg_timeout(void *arg) struct umb_softc *sc = arg; if (sc->sc_info.regstate != MBIM_REGSTATE_ROAMING || sc->sc_roaming) - printf("%s: state change timeout\n",DEVNAM(sc)); + printf("%s: state change timeout\n", DEVNAM(sc)); usb_add_task(sc->sc_udev, &sc->sc_umb_task); } @@ -1617,6 +1615,7 @@ umb_decode_ip_configuration(struct umb_softc *sc, void *data, int len) struct mbim_cid_ipv4_element ipv4elem; struct in_aliasreq ifra; struct sockaddr_in *sin; + struct in_addr addr; int state = -1; int rv; @@ -1639,6 +1638,9 @@ umb_decode_ip_configuration(struct umb_softc *sc, void *data, int len) if (n == 0 || off + sizeof (ipv4elem) > len) goto done; + if (n != 1 && ifp->if_flags & IFF_DEBUG) + log(LOG_INFO, "%s: more than one IPv4 addr: %d\n", + DEVNAM(ifp->if_softc), n); /* Only pick the first one */ memcpy(&ipv4elem, data + off, sizeof (ipv4elem)); @@ -1665,12 +1667,17 @@ umb_decode_ip_configuration(struct umb_softc *sc, void *data, int len) rv = in_ioctl(SIOCAIFADDR, (caddr_t)&ifra, ifp, 1); if (rv == 0) { - if (ifp->if_flags & IFF_DEBUG) + if (ifp->if_flags & IFF_DEBUG) { + char str[3][INET_ADDRSTRLEN]; log(LOG_INFO, "%s: IPv4 addr %s, mask %s, " "gateway %s\n", DEVNAM(ifp->if_softc), - umb_ntop(sintosa(&ifra.ifra_addr)), - umb_ntop(sintosa(&ifra.ifra_mask)), - umb_ntop(sintosa(&ifra.ifra_dstaddr))); + sockaddr_ntop(sintosa(&ifra.ifra_addr), + str[0], sizeof(str[0])), + sockaddr_ntop(sintosa(&ifra.ifra_mask), + str[1], sizeof(str[1])), + sockaddr_ntop(sintosa(&ifra.ifra_dstaddr), + str[2], sizeof(str[2]))); + } state = UMB_S_UP; } else printf("%s: unable to set IPv4 address, error %d\n", @@ -1685,10 +1692,16 @@ umb_decode_ip_configuration(struct umb_softc *sc, void *data, int len) while (n-- > 0) { if (off + sizeof (uint32_t) > len) break; - val = *((uint32_t *)(data + off)); + memcpy(&addr, data + off, sizeof(addr)); if (i < UMB_MAX_DNSSRV) - sc->sc_info.ipv4dns[i++] = val; - off += sizeof (uint32_t); + sc->sc_info.ipv4dns[i++] = addr; + off += sizeof(addr); + if (ifp->if_flags & IFF_DEBUG) { + char str[INET_ADDRSTRLEN]; + log(LOG_INFO, "%s: IPv4 nameserver %s\n", + DEVNAM(ifp->if_softc), inet_ntop(AF_INET, + &addr, str, sizeof(str))); + } } } @@ -2601,31 +2614,6 @@ umb_intr(struct usbd_xfer *xfer, void *priv, usbd_status status) /* * Diagnostic routines */ -char * -umb_ntop(struct sockaddr *sa) -{ -#define NUMBUFS 4 - static char astr[NUMBUFS][INET_ADDRSTRLEN]; - static unsigned nbuf = 0; - char *s; - - s = astr[nbuf++]; - if (nbuf >= NUMBUFS) - nbuf = 0; - - switch (sa->sa_family) { - case AF_INET: - default: - inet_ntop(AF_INET, &satosin(sa)->sin_addr, s, sizeof (astr[0])); - break; - case AF_INET6: - inet_ntop(AF_INET6, &satosin6(sa)->sin6_addr, s, - sizeof (astr[0])); - break; - } - return s; -} - #ifdef UMB_DEBUG char * umb_uuid2str(uint8_t uuid[MBIM_UUID_LEN]) diff --git a/sys/dev/usb/if_umb.h b/sys/dev/usb/if_umb.h index 4bd22b2ee19..391bd6570e9 100644 --- a/sys/dev/usb/if_umb.h +++ b/sys/dev/usb/if_umb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_umb.h,v 1.4 2017/04/18 13:27:55 gerhard Exp $ */ +/* $OpenBSD: if_umb.h,v 1.5 2019/08/26 15:23:01 claudio Exp $ */ /* * Copyright (c) 2016 genua mbH @@ -320,7 +320,7 @@ struct umb_info { uint64_t downlink_speed; #define UMB_MAX_DNSSRV 2 - u_int32_t ipv4dns[UMB_MAX_DNSSRV]; + struct in_addr ipv4dns[UMB_MAX_DNSSRV]; }; #ifdef _KERNEL |