/* All BSD's set IFF_UP on the interface when adding an address.
* But not all BSD's emit this via RTM_IFINFO when they do this ... */
- if (ifam->ifam_type == RTM_NEWADDR && !(ifp->flags & IFF_UP))
- dhcpcd_handlecarrier(ifp, ifp->carrier, ifp->flags | IFF_UP);
+ if (ifam->ifam_type == RTM_NEWADDR && !(ifp->flags & IFF_UP)) {
+ struct ifreq ifr = { .ifr_flags = 0 };
+
+ /* Don't blindly assume the interface is up though.
+ * We might get the address via a state change. */
+ strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
+ if (ioctl(ctx->pf_inet_fd, SIOCGIFFLAGS, &ifr) == -1)
+ return -1;
+ if (ifr.ifr_flags & IFF_UP)
+ dhcpcd_handlecarrier(ifp, ifp->carrier,
+ ifp->flags | IFF_UP);
+ }
switch (rti_info[RTAX_IFA]->sa_family) {
case AF_LINK:
kstat_named_t *knp;
link_state_t linkstate;
- if (if_getflags(ifp) == -1)
- return LINK_UNKNOWN;
-
kcp = kstat_open();
if (kcp == NULL)
goto err;
switch (linkstate) {
case LINK_STATE_UP:
- ifp->flags |= IFF_UP;
+ ifp->flags |= IFF_UP; /* XXX Why? */
return LINK_UP;
case LINK_STATE_DOWN:
return LINK_DOWN;
return ioctl(ctx->pf_inet_fd, req, data, len);
}
-int
-if_getflags(struct interface *ifp)
-{
- struct ifreq ifr = { .ifr_flags = 0 };
-
- strlcpy(ifr.ifr_name, ifp->name, sizeof(ifr.ifr_name));
- if (ioctl(ifp->ctx->pf_inet_fd, SIOCGIFFLAGS, &ifr) == -1)
- return -1;
- ifp->flags = (unsigned int)ifr.ifr_flags;
- return 0;
-}
-
int
if_setflag(struct interface *ifp, short setflag, short unsetflag)
{
#else
#define pioctl(ctx, req, data, len) ioctl((ctx)->pf_inet_fd, (req),(data),(len))
#endif
-int if_getflags(struct interface *);
int if_setflag(struct interface *, short, short);
#define if_up(ifp) if_setflag((ifp), (IFF_UP | IFF_RUNNING), 0)
#define if_down(ifp) if_setflag((ifp), 0, IFF_UP);