]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
BSD: Fix compile on some BSD OS mtu
authorRoy Marples <roy@marples.name>
Sun, 9 Mar 2025 16:11:38 +0000 (16:11 +0000)
committerRoy Marples <roy@marples.name>
Sun, 9 Mar 2025 16:11:38 +0000 (16:11 +0000)
if_mtu is a macro in these headers which conflicts with our function

src/dhcpcd.h
src/if-bsd.c
src/if.c
src/if.h
src/route.c

index 500f043af00a17fad013318083597d17ff87325a..2c5df6d12a0f3cbd95d8535d523aef38276baae0 100644 (file)
@@ -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;
index 4ad41b21b0907509a6b8d1d0d655462d2be0519b..bb9c223a84f4fca58a2dbd7e236c42374e98c8e9 100644 (file)
@@ -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;
index 4db1f8187d555650272eff8d6286d81a9b2f9a39..a74c18c40de734db6e71c9f310ef19b874330ccb 100644 (file)
--- 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
index 1739e2af0d9a3418a295908e338334d4028b72e7..8d1aeccff814f7b5019132370e9dd669e89964e8 100644 (file)
--- 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 *);
 
index beb14226426cbd0e536a8a063cdf5549818b5a2d..865d50a597dfdcc0c88e0fa99b754a2e14c17cf2 100644 (file)
@@ -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