From 733a4733e50b22c8b130c531257779f5eab42973 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Sun, 9 Mar 2025 16:11:38 +0000 Subject: [PATCH] BSD: Fix compile on some BSD OS if_mtu is a macro in these headers which conflicts with our function --- src/dhcpcd.h | 2 +- src/if-bsd.c | 2 +- src/if.c | 14 +------------- src/if.h | 3 +-- src/route.c | 4 ++-- 5 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/dhcpcd.h b/src/dhcpcd.h index 500f043a..2c5df6d1 100644 --- a/src/dhcpcd.h +++ b/src/dhcpcd.h @@ -80,7 +80,7 @@ struct interface { uint16_t hwtype; /* ARPHRD_ETHER for example */ unsigned char hwaddr[HWADDR_LEN]; uint8_t hwlen; - unsigned int mtu; + int mtu; unsigned short vlanid; unsigned int metric; int carrier; diff --git a/src/if-bsd.c b/src/if-bsd.c index 4ad41b21..bb9c223a 100644 --- a/src/if-bsd.c +++ b/src/if-bsd.c @@ -1273,7 +1273,7 @@ if_ifinfo(struct dhcpcd_ctx *ctx, const struct if_msghdr *ifm) if ((ifp = if_findindex(ctx->ifaces, ifm->ifm_index)) == NULL) return 0; - ifp->mtu = if_mtu(ifp); + ifp->mtu = if_getmtu(ifp); link_state = if_carrier(ifp, &ifm->ifm_data); dhcpcd_handlecarrier(ifp, link_state, (unsigned int)ifm->ifm_flags); return 0; diff --git a/src/if.c b/src/if.c index 4db1f818..a74c18c4 100644 --- a/src/if.c +++ b/src/if.c @@ -182,18 +182,6 @@ if_setflag(struct interface *ifp, short setflag, short unsetflag) return 0; } -unsigned int -if_mtu(struct interface *ifp) -{ - struct ifreq ifr = { .ifr_mtu = 0 }; - - strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name)); - if (if_ioctl(ifp->ctx, SIOCGIFMTU, &ifr, sizeof(ifr)) == -1) - return 0; - - return (unsigned int)ifr.ifr_mtu; -} - bool if_is_link_up(const struct interface *ifp) { @@ -697,7 +685,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs, } } - ifp->mtu = if_mtu(ifp); + ifp->mtu = if_getmtu(ifp); ifp->vlanid = if_vlanid(ifp); #ifdef SIOCGIFPRIORITY diff --git a/src/if.h b/src/if.h index 1739e2af..8d1aeccf 100644 --- a/src/if.h +++ b/src/if.h @@ -163,7 +163,7 @@ int if_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t); #define pioctl(ctx, req, data, len) ioctl((ctx)->pf_inet_fd, (req),(data),(len)) #endif int if_setflag(struct interface *, short, short); -unsigned int if_mtu(struct interface *); +int if_getmtu(const struct interface *); #define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING), 0) #define if_down(ifp) if_setflag((ifp), 0, IFF_UP); bool if_is_link_up(const struct interface *); @@ -178,7 +178,6 @@ struct interface *if_find(struct if_head *, const char *); struct interface *if_findindex(struct if_head *, unsigned int); struct interface *if_loopback(struct dhcpcd_ctx *); void if_free(struct interface *); -int if_getmtu(const struct interface *); int if_carrier(struct interface *, const void *); bool if_roaming(struct interface *); diff --git a/src/route.c b/src/route.c index beb14226..865d50a5 100644 --- a/src/route.c +++ b/src/route.c @@ -511,8 +511,8 @@ rt_cmp_misc(struct rt *nrt, struct rt *ort) * if the route does not define it's own. */ unsigned int nmtu, omtu; - nmtu = nrt->rt_mtu ? nrt->rt_mtu : nrt->rt_ifp->mtu; - omtu = ort->rt_mtu ? ort->rt_mtu : ort->rt_ifp->mtu; + nmtu = nrt->rt_mtu ? nrt->rt_mtu : (unsigned int)nrt->rt_ifp->mtu; + omtu = ort->rt_mtu ? ort->rt_mtu : (unsigned int)ort->rt_ifp->mtu; if (omtu != nmtu) return false; #else -- 2.47.2