Skip to content

Commit 733a473

Browse files
committed
BSD: Fix compile on some BSD OS
if_mtu is a macro in these headers which conflicts with our function
1 parent f6983c1 commit 733a473

File tree

5 files changed

+6
-19
lines changed

5 files changed

+6
-19
lines changed

src/dhcpcd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct interface {
8080
uint16_t hwtype; /* ARPHRD_ETHER for example */
8181
unsigned char hwaddr[HWADDR_LEN];
8282
uint8_t hwlen;
83-
unsigned int mtu;
83+
int mtu;
8484
unsigned short vlanid;
8585
unsigned int metric;
8686
int carrier;

src/if-bsd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ if_ifinfo(struct dhcpcd_ctx *ctx, const struct if_msghdr *ifm)
12731273
if ((ifp = if_findindex(ctx->ifaces, ifm->ifm_index)) == NULL)
12741274
return 0;
12751275

1276-
ifp->mtu = if_mtu(ifp);
1276+
ifp->mtu = if_getmtu(ifp);
12771277
link_state = if_carrier(ifp, &ifm->ifm_data);
12781278
dhcpcd_handlecarrier(ifp, link_state, (unsigned int)ifm->ifm_flags);
12791279
return 0;

src/if.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,6 @@ if_setflag(struct interface *ifp, short setflag, short unsetflag)
182182
return 0;
183183
}
184184

185-
unsigned int
186-
if_mtu(struct interface *ifp)
187-
{
188-
struct ifreq ifr = { .ifr_mtu = 0 };
189-
190-
strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
191-
if (if_ioctl(ifp->ctx, SIOCGIFMTU, &ifr, sizeof(ifr)) == -1)
192-
return 0;
193-
194-
return (unsigned int)ifr.ifr_mtu;
195-
}
196-
197185
bool
198186
if_is_link_up(const struct interface *ifp)
199187
{
@@ -697,7 +685,7 @@ if_discover(struct dhcpcd_ctx *ctx, struct ifaddrs **ifaddrs,
697685
}
698686
}
699687

700-
ifp->mtu = if_mtu(ifp);
688+
ifp->mtu = if_getmtu(ifp);
701689
ifp->vlanid = if_vlanid(ifp);
702690

703691
#ifdef SIOCGIFPRIORITY

src/if.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ int if_ioctl(struct dhcpcd_ctx *, ioctl_request_t, void *, size_t);
163163
#define pioctl(ctx, req, data, len) ioctl((ctx)->pf_inet_fd, (req),(data),(len))
164164
#endif
165165
int if_setflag(struct interface *, short, short);
166-
unsigned int if_mtu(struct interface *);
166+
int if_getmtu(const struct interface *);
167167
#define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING), 0)
168168
#define if_down(ifp) if_setflag((ifp), 0, IFF_UP);
169169
bool if_is_link_up(const struct interface *);
@@ -178,7 +178,6 @@ struct interface *if_find(struct if_head *, const char *);
178178
struct interface *if_findindex(struct if_head *, unsigned int);
179179
struct interface *if_loopback(struct dhcpcd_ctx *);
180180
void if_free(struct interface *);
181-
int if_getmtu(const struct interface *);
182181
int if_carrier(struct interface *, const void *);
183182
bool if_roaming(struct interface *);
184183

src/route.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ rt_cmp_misc(struct rt *nrt, struct rt *ort)
511511
* if the route does not define it's own. */
512512
unsigned int nmtu, omtu;
513513

514-
nmtu = nrt->rt_mtu ? nrt->rt_mtu : nrt->rt_ifp->mtu;
515-
omtu = ort->rt_mtu ? ort->rt_mtu : ort->rt_ifp->mtu;
514+
nmtu = nrt->rt_mtu ? nrt->rt_mtu : (unsigned int)nrt->rt_ifp->mtu;
515+
omtu = ort->rt_mtu ? ort->rt_mtu : (unsigned int)ort->rt_ifp->mtu;
516516
if (omtu != nmtu)
517517
return false;
518518
#else

0 commit comments

Comments
 (0)