Correct duid generate on FreeBSD

This commit is contained in:
Simon Kelley
2012-02-11 22:01:50 +00:00
parent 98d76a0326
commit 6aef600d48
4 changed files with 32 additions and 38 deletions

View File

@@ -108,6 +108,10 @@ int iface_enumerate(int family, void *parm, int (*callback)())
return 0; /* need code for Solaris and MacOS*/ return 0; /* need code for Solaris and MacOS*/
#endif #endif
/* AF_LINK doesn't exist in Linux, so we can't use it in our API */
if (family == AF_LOCAL)
family = AF_LINK;
if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) == -1) if ((fd = socket(PF_INET, SOCK_DGRAM, 0)) == -1)
return 0; return 0;
@@ -154,24 +158,6 @@ int iface_enumerate(int family, void *parm, int (*callback)())
ifr = (struct ifreq *)ifreq.iov_base; ifr = (struct ifreq *)ifreq.iov_base;
memcpy(ifr, ptr, len); memcpy(ifr, ptr, len);
#ifdef HAVE_DHCP6
if (family == AF_LOCAL)
{
unsigned int flags;
if (ioctl(fd, SIOCGIFFLAGS, ifr) != -1)
{
flags = ifr->ifr_flags;
ifr->ifr_addr.sa_family = AF_LINK;
if (ioctl(fd, SIOCGIFADDR, ifr) != -1 &&
!((*callback)((unsigned int)htons(ETHERTYPE_IP),
flags,
LLADDR((struct sockaddr_dl *)&ifr->ifr_addr), ETHER_ADDR_LEN, parm)))
goto err;
}
continue;
}
#endif
if (ifr->ifr_addr.sa_family == family) if (ifr->ifr_addr.sa_family == family)
{ {
if (family == AF_INET) if (family == AF_INET)
@@ -207,6 +193,15 @@ int iface_enumerate(int family, void *parm, int (*callback)())
parm))) parm)))
goto err; goto err;
} }
#endif
#ifdef HAVE_DHCP6
else if (family == AF_LINK)
{
/* Assume ethernet again here */
struct sockaddr_dl *sdl = (struct sockaddr_dl *)&ifr->ifr_addr;
if (sdl->sdl_alen != 0 && !((*callback)(ARPHRD_ETHER, LLADDR(sdl), sdl->sdl_alen, parm)))
goto err;
}
#endif #endif
} }
} }

View File

@@ -34,8 +34,7 @@ static int join_multicast(struct in6_addr *local, int prefix,
static int complete_context6(struct in6_addr *local, int prefix, static int complete_context6(struct in6_addr *local, int prefix,
int scope, int if_index, int dad, void *vparam); int scope, int if_index, int dad, void *vparam);
static int make_duid1(unsigned int type, unsigned int flags, char *mac, static int make_duid1(unsigned int type, char *mac, size_t maclen, void *parm);
size_t maclen, void *parm);
void dhcp6_init(void) void dhcp6_init(void)
{ {
@@ -477,23 +476,20 @@ void make_duid(time_t now)
{ {
/* rebase epoch to 1/1/2000 */ /* rebase epoch to 1/1/2000 */
time_t newnow = now - 946684800; time_t newnow = now - 946684800;
iface_enumerate(AF_LOCAL, &newnow, make_duid1); iface_enumerate(AF_LOCAL, &newnow, make_duid1);
if (!daemon->duid) if(!daemon->duid)
die("Cannot create DHCPv6 server DUID", NULL, EC_MISC); die("Cannot create DHCPv6 server DUID: %s", NULL, EC_MISC);
} }
static int make_duid1(unsigned int type, unsigned int flags, char *mac, static int make_duid1(unsigned int type, char *mac, size_t maclen, void *parm)
size_t maclen, void *parm)
{ {
/* create DUID as specified in RFC3315. We use the MAC of the /* create DUID as specified in RFC3315. We use the MAC of the
first interface we find that isn't loopback or P-to-P */ first interface we find that isn't loopback or P-to-P */
unsigned char *p; unsigned char *p;
if (flags & (IFF_LOOPBACK | IFF_POINTOPOINT))
return 1;
daemon->duid = p = safe_malloc(maclen + 8); daemon->duid = p = safe_malloc(maclen + 8);
daemon->duid_len = maclen + 8; daemon->duid_len = maclen + 8;

View File

@@ -148,12 +148,6 @@ void lease_init(time_t now)
lease->flags &= ~(LEASE_NEW | LEASE_CHANGED); lease->flags &= ~(LEASE_NEW | LEASE_CHANGED);
} }
#ifdef HAVE_DHCP6
/* If we're not doing DHCPv6, and there are not v6 leases, don't add the DUID to the database */
if (!daemon->duid && daemon->dhcp6)
make_duid(now);
#endif
#ifdef HAVE_SCRIPT #ifdef HAVE_SCRIPT
if (!daemon->lease_stream) if (!daemon->lease_stream)
{ {
@@ -181,6 +175,16 @@ void lease_init(time_t now)
file_dirty = 0; file_dirty = 0;
lease_prune(NULL, now); lease_prune(NULL, now);
dns_dirty = 1; dns_dirty = 1;
#ifdef HAVE_DHCP6
/* If we're not doing DHCPv6, and there are not v6 leases, don't add the DUID to the database */
if (!daemon->duid && daemon->dhcp6)
{
file_dirty = 1;
make_duid(now);
}
#endif
} }
void lease_update_from_configs(void) void lease_update_from_configs(void)

View File

@@ -282,9 +282,8 @@ int iface_enumerate(int family, void *parm, int (*callback)())
rta = RTA_NEXT(rta, len1); rta = RTA_NEXT(rta, len1);
} }
if (mac && !((*callback)((unsigned int)link->ifi_type, if (mac && !((link->ifi_flags & (IFF_LOOPBACK | IFF_POINTOPOINT))) &&
(unsigned int)link->ifi_flags, !((*callback)((unsigned int)link->ifi_type, mac, maclen, parm)))
mac, maclen, parm)))
return 0; return 0;
} }
#endif #endif