View | Details | Raw Unified
Collapse All | Expand All

(-) tags/dhcpcd-3.1.1/ChangeLog (+6 lines)
 Lines 1-3    Link Here 
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
dhcpcd-3.1.1
Fix segfault in arp code that some users had.
Fix segfault in arp code that some users had.
Remove getifaddrs code and instead just use ioctls so we don't break
Remove getifaddrs code and instead just use ioctls so we don't break
(-) tags/dhcpcd-3.1.1/client.c (-1 lines)
 Lines 502-508    Link Here 
					xid = random ();
					xid = random ();
				case STATE_RENEWING:
				case STATE_RENEWING:
					iface->start_uptime = uptime ();
					iface->start_uptime = uptime ();
					free_dhcp (dhcp);
					logger (LOG_INFO, "renewing lease of %s", inet_ntoa
					logger (LOG_INFO, "renewing lease of %s", inet_ntoa
							(dhcp->address));
							(dhcp->address));
					SOCKET_MODE (SOCKET_OPEN);
					SOCKET_MODE (SOCKET_OPEN);
(-) tags/dhcpcd-3.1.1/config.h (-4 / +6 lines)
 Lines 43-49    Link Here 
 * See RFC 3315 for details on this. */
 * See RFC 3315 for details on this. */
#define ENABLE_DUID
#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"
#define PACKAGE             "dhcpcd"
 Lines 54-70    Link Here 
#define NISFILE             ETCDIR "/yp.conf"
#define NISFILE             ETCDIR "/yp.conf"
#define NISSERVICE          ETCDIR "/init.d/ypbind"
#define NISSERVICE          ETCDIR "/init.d/ypbind"
#define NISRESTARTARGS      "--quiet", "conditionalrestart"
#define NISRESTARTARGS      "--nodeps", "--quiet", "conditionalrestart"
#define NTPFILE             ETCDIR "/ntp.conf"
#define NTPFILE             ETCDIR "/ntp.conf"
#define NTPDRIFTFILE        ETCDIR "/ntp.drift"
#define NTPDRIFTFILE        ETCDIR "/ntp.drift"
#define NTPLOGFILE          "/var/log/ntp.log"
#define NTPLOGFILE          "/var/log/ntp.log"
#define NTPSERVICE          ETCDIR "/init.d/ntpd"
#define NTPSERVICE          ETCDIR "/init.d/ntpd"
#define NTPRESTARTARGS      "--quiet", "conditionalrestart"
#define NTPRESTARTARGS      "--nodeps", "--quiet", "conditionalrestart"
#define OPENNTPFILE         ETCDIR "/ntpd.conf"
#define OPENNTPFILE         ETCDIR "/ntpd.conf"
#define OPENNTPSERVICE      ETCDIR "/init.d/ntpd"
#define OPENNTPSERVICE      ETCDIR "/init.d/ntpd"
#define OPENNTPRESTARTARGS  "--quiet", "conditionalrestart"
#define OPENNTPRESTARTARGS  "--nodeps", "--quiet", "conditionalrestart"
#define DEFAULT_SCRIPT      ETCDIR "/" PACKAGE ".sh"
#define DEFAULT_SCRIPT      ETCDIR "/" PACKAGE ".sh"
(-) tags/dhcpcd-3.1.1/dhcp.c (-11 / +29 lines)
 Lines 374-389    Link Here 
		memset (route, 0, sizeof (route_t));
		memset (route, 0, sizeof (route_t));
		cidr = *q++;
		cidr = *q++;
		if (cidr == 0)
		ocets = (cidr + 7) / 8;
			ocets = 0;
		else if (cidr < 9)
			ocets = 1;
		else if (cidr < 17)
			ocets = 2;
		else if (cidr < 25)
			ocets = 3;
		else
			ocets = 4;
		if (ocets > 0) {
		if (ocets > 0) {
			memcpy (&route->destination.s_addr, q, ocets);
			memcpy (&route->destination.s_addr, q, ocets);
 Lines 501-506    Link Here 
	return (sip);
	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)
int parse_dhcpmessage (dhcp_t *dhcp, const dhcpmessage_t *message)
{
{
	const unsigned char *p = message->options;
	const unsigned char *p = message->options;
 Lines 714-720    Link Here 
					memcpy (&static_routesp->destination.s_addr, p + i, 4);
					memcpy (&static_routesp->destination.s_addr, p + i, 4);
					memcpy (&static_routesp->gateway.s_addr, p + i + 4, 4);
					memcpy (&static_routesp->gateway.s_addr, p + i + 4, 4);
					static_routesp->netmask.s_addr =
					static_routesp->netmask.s_addr =
						get_netmask (static_routesp->destination.s_addr); 
						route_netmask (static_routesp->destination.s_addr); 
				}
				}
				break;
				break;
(-) tags/dhcpcd-3.1.1/interface.c (-47 / +52 lines)
 Lines 441-446    Link Here 
	return (r == 0 ? 0 : -1);
	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__) \
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined (__OpenBSD__) \
|| defined(__APPLE__)
|| defined(__APPLE__)
static int do_address (const char *ifname, struct in_addr address,
static int do_address (const char *ifname, struct in_addr address,
 Lines 494-500    Link Here 
					 int change, int del)
					 int change, int del)
{
{
	int s;
	int s;
	char *dstd;
	struct rtm 
	struct rtm 
	{
	{
		struct rt_msghdr hdr;
		struct rt_msghdr hdr;
 Lines 517-540    Link Here 
	if (! ifname)
	if (! ifname)
		return -1;
		return -1;
	/* Do something with metric to satisfy compiler warnings */
	log_route (destination, netmask, gateway, metric, change, del);
	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);
	if ((s = socket (PF_ROUTE, SOCK_RAW, 0)) == -1) {
	if ((s = socket (PF_ROUTE, SOCK_RAW, 0)) == -1) {
		logger (LOG_ERR, "socket: %s", strerror (errno));
		logger (LOG_ERR, "socket: %s", strerror (errno));
 Lines 546-557    Link Here 
	rtm.hdr.rtm_version = RTM_VERSION;
	rtm.hdr.rtm_version = RTM_VERSION;
	rtm.hdr.rtm_seq = ++seq;
	rtm.hdr.rtm_seq = ++seq;
	rtm.hdr.rtm_type = change ? RTM_CHANGE : del ? RTM_DELETE : RTM_ADD;
	rtm.hdr.rtm_type = change ? RTM_CHANGE : del ? RTM_DELETE : RTM_ADD;
	rtm.hdr.rtm_flags = RTF_UP | RTF_STATIC;
	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 */
	/* This order is important */
	rtm.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
	rtm.hdr.rtm_addrs = RTA_DST | RTA_GATEWAY | RTA_NETMASK;
 Lines 585-592    Link Here 
		l = SA_SIZE (&(su.sa));
		l = SA_SIZE (&(su.sa));
		memcpy (bp, &su, l);
		memcpy (bp, &su, l);
		bp += l;
		bp += l;
		rtm.hdr.rtm_flags |= RTF_HOST;
	} else {
	} else {
		ADDADDR (gateway);
		ADDADDR (gateway);
		rtm.hdr.rtm_flags |= RTF_GATEWAY;
	}
	}
	ADDADDR (netmask);
	ADDADDR (netmask);
 Lines 838-845    Link Here 
					 struct in_addr gateway,
					 struct in_addr gateway,
					 int metric, int change, int del)
					 int metric, int change, int del)
{
{
	char *dstd;
	char *gend;
	unsigned int ifindex;
	unsigned int ifindex;
	struct
	struct
	{
	{
 Lines 852-875    Link Here 
	if (! ifname)
	if (! ifname)
		return -1;
		return -1;
	dstd = xstrdup (inet_ntoa (destination));
	log_route (destination, netmask, gateway, metric, change, del);
	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);
	memset (&nlm, 0, sizeof (nlm));
	memset (&nlm, 0, sizeof (nlm));
 Lines 888-894    Link Here 
	else {
	else {
		nlm.hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL;
		nlm.hdr.nlmsg_flags |= NLM_F_CREATE | NLM_F_EXCL;
		nlm.rt.rtm_protocol = RTPROT_BOOT;
		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;
			nlm.rt.rtm_scope = RT_SCOPE_LINK;
		else
		else
			nlm.rt.rtm_scope = RT_SCOPE_UNIVERSE;
			nlm.rt.rtm_scope = RT_SCOPE_UNIVERSE;
 Lines 898-908    Link Here 
	nlm.rt.rtm_dst_len = inet_ntocidr (netmask);
	nlm.rt.rtm_dst_len = inet_ntocidr (netmask);
	add_attr_l (&nlm.hdr, sizeof (nlm), RTA_DST, &destination.s_addr,
	add_attr_l (&nlm.hdr, sizeof (nlm), RTA_DST, &destination.s_addr,
				sizeof (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,
		add_attr_l (&nlm.hdr, sizeof (nlm), RTA_GATEWAY, &gateway.s_addr,
					sizeof (gateway.s_addr));
					sizeof (gateway.s_addr));
	if (! (ifindex = if_nametoindex (ifname))) {
	if (! (ifindex = if_nametoindex (ifname))) {
		logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
		logger (LOG_ERR, "if_nametoindex: Couldn't find index for interface `%s'",
				ifname);
				ifname);