Common subdirectories: tags/dhcpcd-3.1.1/.svn and trunk/.svn diff -u tags/dhcpcd-3.1.1/ChangeLog trunk/ChangeLog --- tags/dhcpcd-3.1.1/ChangeLog 2007-07-26 10:35:44 +0100 +++ trunk/ChangeLog 2007-07-30 16:43:30 +0100 @@ -1,3 +1,9 @@ +Use a generic route logger. +Fix static route netmask calculation and applicaton. +Use --nodeps when restarting services. +Simply CIDR calculation, thanks to Francois-Xavier Le Bail. +Don't free the dhcp object on RENEW (fixes a segfault). + dhcpcd-3.1.1 Fix segfault in arp code that some users had. Remove getifaddrs code and instead just use ioctls so we don't break diff -u tags/dhcpcd-3.1.1/client.c trunk/client.c --- tags/dhcpcd-3.1.1/client.c 2007-07-26 10:35:44 +0100 +++ trunk/client.c 2007-07-28 16:15:00 +0100 @@ -502,7 +502,6 @@ xid = random (); case STATE_RENEWING: iface->start_uptime = uptime (); - free_dhcp (dhcp); logger (LOG_INFO, "renewing lease of %s", inet_ntoa (dhcp->address)); SOCKET_MODE (SOCKET_OPEN); diff -u tags/dhcpcd-3.1.1/config.h trunk/config.h --- tags/dhcpcd-3.1.1/config.h 2007-07-26 10:35:44 +0100 +++ trunk/config.h 2007-07-30 13:44:25 +0100 @@ -43,7 +43,9 @@ * See RFC 3315 for details on this. */ #define ENABLE_DUID -/* Packname name and pathname definitions */ +/* Packname name and pathname definitions. + * NOTE: The service restart commands are Gentoo specific and will + * probably need to be adapted for your OS. */ #define PACKAGE "dhcpcd" @@ -54,17 +56,17 @@ #define NISFILE ETCDIR "/yp.conf" #define NISSERVICE ETCDIR "/init.d/ypbind" -#define NISRESTARTARGS "--quiet", "conditionalrestart" +#define NISRESTARTARGS "--nodeps", "--quiet", "conditionalrestart" #define NTPFILE ETCDIR "/ntp.conf" #define NTPDRIFTFILE ETCDIR "/ntp.drift" #define NTPLOGFILE "/var/log/ntp.log" #define NTPSERVICE ETCDIR "/init.d/ntpd" -#define NTPRESTARTARGS "--quiet", "conditionalrestart" +#define NTPRESTARTARGS "--nodeps", "--quiet", "conditionalrestart" #define OPENNTPFILE ETCDIR "/ntpd.conf" #define OPENNTPSERVICE ETCDIR "/init.d/ntpd" -#define OPENNTPRESTARTARGS "--quiet", "conditionalrestart" +#define OPENNTPRESTARTARGS "--nodeps", "--quiet", "conditionalrestart" #define DEFAULT_SCRIPT ETCDIR "/" PACKAGE ".sh" diff -u tags/dhcpcd-3.1.1/dhcp.c trunk/dhcp.c --- tags/dhcpcd-3.1.1/dhcp.c 2007-07-26 10:35:44 +0100 +++ trunk/dhcp.c 2007-07-30 15:26:36 +0100 @@ -374,16 +374,7 @@ memset (route, 0, sizeof (route_t)); cidr = *q++; - if (cidr == 0) - ocets = 0; - else if (cidr < 9) - ocets = 1; - else if (cidr < 17) - ocets = 2; - else if (cidr < 25) - ocets = 3; - else - ocets = 4; + ocets = (cidr + 7) / 8; if (ocets > 0) { memcpy (&route->destination.s_addr, q, ocets); @@ -501,6 +492,33 @@ return (sip); } +/* This calculates the netmask that we should use for static routes. + * This IS different from the calculation used to calculate the netmask + * for an interface address. */ +static unsigned long route_netmask (unsigned long ip_in) +{ + unsigned long p = ntohl (ip_in); + unsigned long t; + + if (IN_CLASSA (p)) + t = ~IN_CLASSA_NET; + else { + if (IN_CLASSB (p)) + t = ~IN_CLASSB_NET; + else { + if (IN_CLASSC (p)) + t = ~IN_CLASSC_NET; + else + t = 0; + } + } + + while (t & p) + t >>= 1; + + return (htonl (~t)); +} + int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message) { const unsigned char *p = message->options; @@ -714,7 +732,7 @@ memcpy (&static_routesp->destination.s_addr, p + i, 4); memcpy (&static_routesp->gateway.s_addr, p + i + 4, 4); static_routesp->netmask.s_addr = - get_netmask (static_routesp->destination.s_addr); + route_netmask (static_routesp->destination.s_addr); } break; Only in tags/dhcpcd-3.1.1: dhcpcd-3.1.1.tar.bz2 diff -u tags/dhcpcd-3.1.1/interface.c trunk/interface.c --- tags/dhcpcd-3.1.1/interface.c 2007-07-26 10:35:44 +0100 +++ trunk/interface.c 2007-07-30 16:30:11 +0100 @@ -441,6 +441,51 @@ return (r == 0 ? 0 : -1); } +static void log_route( + struct in_addr destination, + struct in_addr netmask, + struct in_addr gateway, + int metric, + int change, int del) +{ + char *dstd = xstrdup (inet_ntoa (destination)); + +#ifdef __linux__ +#define METRIC " metric %d" +#else +#define METRIC "" + metric = 0; +#endif + + if (gateway.s_addr == destination.s_addr) + logger (LOG_INFO, "%s route to %s/%d" METRIC, + change ? "changing" : del ? "removing" : "adding", + dstd, inet_ntocidr (netmask) +#ifdef __linux__ + , metric +#endif + ); + else if (destination.s_addr == INADDR_ANY) + logger (LOG_INFO, "%s default route via %s" METRIC, + change ? "changing" : del ? "removing" : "adding", + inet_ntoa (gateway) + +#ifdef __linux__ + , metric +#endif + ); + else + logger (LOG_INFO, "%s route to %s/%d via %s" METRIC, + change ? "changing" : del ? "removing" : "adding", + dstd, inet_ntocidr (netmask), inet_ntoa (gateway) +#ifdef __linux__ + , metric +#endif + ); + + free (dstd); +} + #if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__) \ || defined(__APPLE__) static int do_address (const char *ifname, struct in_addr address, @@ -494,7 +539,6 @@ int change, int del) { int s; - char *dstd; struct rtm { struct rt_msghdr hdr; @@ -517,24 +561,7 @@ if (! ifname) return -1; - /* Do something with metric to satisfy compiler warnings */ - metric = 0; - - dstd = xstrdup (inet_ntoa (destination)); - if (gateway.s_addr == destination.s_addr) - logger (LOG_INFO, "%s route to %s/%d", - change ? "changing" : del ? "removing" : "adding", - dstd, inet_ntocidr (netmask)); - else if (destination.s_addr == INADDR_ANY) - logger (LOG_INFO, "%s default route via %s", - change ? "changing" : del ? "removing" : "adding", - inet_ntoa (gateway)); - else - logger (LOG_INFO, "%s route to %s/%d via %s", - change ? "changing" : del ? "removing" : "adding", - dstd, inet_ntocidr (netmask), inet_ntoa (gateway)); - if (dstd) - free (dstd); + log_route (destination, netmask, gateway, metric, change, del); if ((s = socket (PF_ROUTE, SOCK_RAW, 0)) == -1) { logger (LOG_ERR, "socket: %s", strerror (errno)); @@ -546,12 +573,7 @@ rtm.hdr.rtm_version = RTM_VERSION; rtm.hdr.rtm_seq = ++seq; rtm.hdr.rtm_type = change ? RTM_CHANGE : del ? RTM_DELETE : RTM_ADD; - rtm.hdr.rtm_flags = RTF_UP | RTF_STATIC; - if (netmask.s_addr == INADDR_BROADCAST) - rtm.hdr.rtm_flags |= RTF_HOST; - else - rtm.hdr.rtm_flags |= RTF_GATEWAY; /* This order is important */ rtm.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK; @@ -585,8 +607,11 @@ l = SA_SIZE (&(su.sa)); memcpy (bp, &su, l); bp += l; + + rtm.hdr.rtm_flags |= RTF_HOST; } else { ADDADDR (gateway); + rtm.hdr.rtm_flags |= RTF_GATEWAY; } ADDADDR (netmask); @@ -838,8 +863,6 @@ struct in_addr gateway, int metric, int change, int del) { - char *dstd; - char *gend; unsigned int ifindex; struct { @@ -852,24 +875,7 @@ if (! ifname) return -1; - dstd = xstrdup (inet_ntoa (destination)); - gend = xstrdup (inet_ntoa (netmask)); - if (gateway.s_addr == destination.s_addr) - logger (LOG_INFO, "%s route to %s (%s) metric %d", - change ? "changing" : del ? "removing" : "adding", - dstd, gend, metric); - else if (destination.s_addr == INADDR_ANY && netmask.s_addr == INADDR_ANY) - logger (LOG_INFO, "%s default route via %s metric %d", - change ? "changing" : del ? "removing" : "adding", - inet_ntoa (gateway), metric); - else - logger (LOG_INFO, "%s route to %s (%s) via %s metric %d", - change ? "changing" : del ? "removing" : "adding", - dstd, gend, inet_ntoa (gateway), metric); - if (dstd) - free (dstd); - if (gend) - free (gend); + log_route (destination, netmask, gateway, metric, change, del); memset (&nlm, 0, sizeof (nlm)); @@ -888,7 +894,7 @@ else { nlm.hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL; nlm.rt.rtm_protocol = RTPROT_BOOT; - if (gateway.s_addr == INADDR_ANY) + if (netmask.s_addr == INADDR_BROADCAST) nlm.rt.rtm_scope = RT_SCOPE_LINK; else nlm.rt.rtm_scope = RT_SCOPE_UNIVERSE; @@ -898,11 +904,10 @@ nlm.rt.rtm_dst_len = inet_ntocidr (netmask); add_attr_l (&nlm.hdr, sizeof (nlm), RTA_DST, &destination.s_addr, sizeof (destination.s_addr)); - if (gateway.s_addr != INADDR_ANY && gateway.s_addr != destination.s_addr) + if (netmask.s_addr != INADDR_BROADCAST) add_attr_l (&nlm.hdr, sizeof (nlm), RTA_GATEWAY, &gateway.s_addr, sizeof (gateway.s_addr)); - if (! (ifindex = if_nametoindex (ifname))) { logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'", ifname);