Remove link_addr compact function as we now had a LL address list.
Fix INET and INET6 seperate compiles.
+++ /dev/null
-/*-
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)linkaddr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <net/if_dl.h>
-
-#include <string.h>
-
-/* States*/
-#define NAMING 0
-#define GOTONE 1
-#define GOTTWO 2
-#define RESET 3
-/* Inputs */
-#define DIGIT (4*0)
-#define END (4*1)
-#define DELIM (4*2)
-#define LETTER (4*3)
-
-void
-link_addr(addr, sdl)
- const char *addr;
- struct sockaddr_dl *sdl;
-{
- char *cp = sdl->sdl_data;
- char *cplim = sdl->sdl_len + (char *)(void *)sdl;
- int byte = 0, state = NAMING;
- int newaddr = 0;
-
- (void)memset(&sdl->sdl_family, 0, (size_t)sdl->sdl_len - 1);
- sdl->sdl_family = AF_LINK;
- do {
- state &= ~LETTER;
- if ((*addr >= '0') && (*addr <= '9')) {
- newaddr = *addr - '0';
- } else if ((*addr >= 'a') && (*addr <= 'f')) {
- newaddr = *addr - 'a' + 10;
- } else if ((*addr >= 'A') && (*addr <= 'F')) {
- newaddr = *addr - 'A' + 10;
- } else if (*addr == 0) {
- state |= END;
- } else if (state == NAMING &&
- (((*addr >= 'A') && (*addr <= 'Z')) ||
- ((*addr >= 'a') && (*addr <= 'z'))))
- state |= LETTER;
- else
- state |= DELIM;
- addr++;
- switch (state /* | INPUT */) {
- case NAMING | DIGIT:
- case NAMING | LETTER:
- *cp++ = addr[-1];
- continue;
- case NAMING | DELIM:
- state = RESET;
- sdl->sdl_nlen = cp - sdl->sdl_data;
- continue;
- case GOTTWO | DIGIT:
- *cp++ = byte;
- /* FALLTHROUGH */
- case RESET | DIGIT:
- state = GOTONE;
- byte = newaddr;
- continue;
- case GOTONE | DIGIT:
- state = GOTTWO;
- byte = newaddr + (byte << 4);
- continue;
- default: /* | DELIM */
- state = RESET;
- *cp++ = byte;
- byte = 0;
- continue;
- case GOTONE | END:
- case GOTTWO | END:
- *cp++ = byte;
- /* FALLTHROUGH */
- case RESET | END:
- break;
- }
- break;
- } while (cp < cplim);
- sdl->sdl_alen = cp - LLADDR(sdl);
- newaddr = cp - (char *)(void *)sdl;
- if ((size_t) newaddr > sizeof(*sdl))
- sdl->sdl_len = newaddr;
- return;
-}
echo "SRCS+= bpf.c" >>$CONFIG_MK
fi
echo "SRCS+= if-bsd.c platform-bsd.c" >>$CONFIG_MK
- echo "COMPAT_SRCS+= compat/linkaddr.c" >>$CONFIG_MK
echo "LDADD+= -lrt" >>$CONFIG_MK
;;
*)
#define dhcp_drop(a, b)
#define dhcp_start(a) {}
#define dhcp_reboot(a, b) b = b
+#define dhcp_reboot_newopts(a, b)
#define dhcp_close(a)
#define dhcp_free(a)
#define dhcp_dump(a) -1
#else
#define dhcp6_printoptions()
#define dhcp6_addrexists(a)
-#define dhcp6_find_delegates(a);
+#define dhcp6_find_delegates(a) 0
#define dhcp6_start(a, b) 0
#define dhcp6_reboot(a)
#define dhcp6_env(a, b, c, d, e)
char *bp = rtm.buffer;
size_t l;
int retval = 0;
+ const struct ipv6_addr_l *lla;
/* KAME based systems want to store the scope inside the sin6_addr
* for link local addreses */
ADDADDR(&rt->dest);
if (!(rtm.hdr.rtm_flags & RTF_GATEWAY)) {
- /* Make us a link layer socket for the host gateway */
- memset(&su, 0, sizeof(su));
- su.sdl.sdl_len = sizeof(struct sockaddr_dl);
- link_addr(rt->iface->name, &su.sdl);
- ADDSU;
+ lla = ipv6_linklocal(rt->iface);
+ if (lla == NULL) /* unlikely as we need a LL to get here */
+ return -1;
+ ADDADDRS(&lla->addr, rt->iface->index);
} else
ADDADDRS(&rt->gate, rt->iface->index);
retval = -1;
return retval;
}
-
-int
-pfx_flush(void)
-{
- int s;
- char dummy[IFNAMSIZ + 1];
-
- s = socket(AF_INET6, SOCK_DGRAM, 0);
- if (s != -1) {
- strcpy(dummy, "lo0");
- s = ioctl(s, SIOCSPFXFLUSH_IN6, (caddr_t)&dummy);
- }
- return s;
-}
#endif
static void
}
}
+#ifdef INET6
int
in6_addr_flags(const char *ifname, const struct in6_addr *addr)
{
}
return flags;
}
+#endif
int
manage_link(int fd)
struct if_announcemsghdr *ifan;
struct if_msghdr *ifm;
struct ifa_msghdr *ifam;
- struct rt rt;
struct sockaddr *sa, *rti_info[RTAX_MAX];
int len;
#ifdef RTM_CHGADDR
struct sockaddr_dl sdl;
unsigned char *hwaddr;
#endif
+#ifdef INET
+ struct rt rt;
+#endif
#if defined(INET6) && !defined(LISTEN_DAD)
struct in6_addr ia6;
struct sockaddr_in6 *sin6;
/* How do I get IPv6 address flags on Linux? */
return 0;
}
-
-int
-pfx_flush(void)
-{
-
- /* Flush prefixes, ip -6 neigh flush equivalent */
- /* There seems to be no need for this on Linux right now though,
- * probably due to route metrics */
- return 0;
-}
#endif
return v;
}
+#ifdef INET
static int
parse_addr(struct in_addr *addr, struct in_addr *net, const char *arg)
{
-#ifdef INET
char *p;
int i;
else if (net != NULL)
net->s_addr = ipv4_getnetmask(addr->s_addr);
return 0;
+}
#else
+static int
+parse_addr(__unused struct in_addr *addr, __unused struct in_addr *net,
+ __unused const char *arg)
+{
+
syslog(LOG_ERR, "No IPv4 support");
return -1;
-#endif
}
+#endif
static const char *
set_option_space(const char *arg, const struct dhcp_opt **d,
parse_option(struct if_options *ifo, int opt, const char *arg)
{
int i;
- long l;
char *p = NULL, *fp, *np, **nconf;
ssize_t s;
- size_t sl;
struct in_addr addr, addr2;
in_addr_t *naddr;
struct rt *rt;
const struct dhcp_opt *d;
uint8_t *request, *require, *no;
+#ifdef INET6
+ long l;
uint32_t u32;
+ size_t sl;
struct if_iaid *iaid;
uint8_t _iaid[4];
struct if_sla *sla, *slap;
+#endif
i = 0;
switch(opt) {
#define EUI64_GROUP(in6) ((in6)->s6_addr[8] & EUI64_GBIT)
static struct rt6head *routes;
-static uint8_t do_pfx_flush;
#ifdef DEBUG_MEMORY
static void
ap->flags |= IPV6_AF_ADDED;
if (ap->delegating_iface)
ap->flags |= IPV6_AF_DELEGATED;
+#if HAVE_ROUTE_METRIC
if (ap->iface->options->options & DHCPCD_IPV6RA_OWN &&
ipv6_removesubnet(ap->iface, ap) == -1)
syslog(LOG_ERR,"ipv6_removesubnet %m");
+#endif
if (ap->prefix_pltime == ND6_INFINITE_LIFETIME &&
ap->prefix_vltime == ND6_INFINITE_LIFETIME)
syslog(LOG_DEBUG,
desc_route(add ? "adding" : "changing", nrt);
/* We delete and add the route so that we can change metric and
* prefer the interface. */
- if (del_route6(ort) == 0 && add)
- do_pfx_flush = 1;
+ del_route6(ort);
if (add_route6(nrt) == 0)
return 0;
syslog(LOG_ERR, "%s: add_route6: %m", nrt->iface->name);
return r;
}
+#if HAVE_ROUTE_METRIC
int
ipv6_removesubnet(const struct interface *ifp, struct ipv6_addr *addr)
{
}
return r;
}
+#endif
#define RT_IS_DEFAULT(rtp) \
(IN6_ARE_ADDR_EQUAL(&((rtp)->dest), &in6addr_any) && \
return;
}
TAILQ_INIT(nrs);
- have_default = do_pfx_flush = 0;
+ have_default = 0;
TAILQ_FOREACH_SAFE(rt, &dnr, next, rtn) {
/* Is this route already in our table? */
if (find_route6(nrs, rt) != NULL)
{
if (c_route(or, rt) != 0)
continue;
- do_pfx_flush = 1;
}
TAILQ_REMOVE(routes, or, next);
free(or);
free(rt);
}
- if (do_pfx_flush) {
- /* We need to flush all entries in our prefix list
- * if we changed a route so that we leave via the
- * correct interface */
- if (pfx_flush() == -1)
- syslog(LOG_ERR, "pfx_flush: %m");
-
- /* XXX FIXME
- * On multi-homed systems on the same network
- * (ie wired and wireless) swapping the active routes
- * between interfaces (ie, bringing down the wired and
- * back up again while wireless is active) causes the
- * ping6 command to emit bogus Network is down errors.
- * This could be a kernel bug though */
- }
-
free(routes);
routes = nrs;
}
#define ROUNDUP8(a) (1 + (((a) - 1) | 7))
-#ifdef INET6
#ifndef ND6_INFINITE_LIFETIME
# define ND6_INFINITE_LIFETIME ((uint32_t)~0)
#endif
#define IPV6_CSTATE(ifp) \
((const struct ipv6_state *)(ifp)->if_data[IF_DATA_IPV6])
+#ifdef INET6
int ipv6_init(void);
ssize_t ipv6_printaddr(char *, ssize_t, const uint8_t *, const char *);
int ipv6_makeaddr(struct in6_addr *, const struct interface *,
void ipv6_free(struct interface *);
int ipv6_removesubnet(const struct interface *, struct ipv6_addr *);
void ipv6_buildroutes(void);
+
+int if_address6(const struct ipv6_addr *, int);
+#define add_address6(a) if_address6(a, 1)
+#define del_address6(a) if_address6(a, -1)
+int in6_addr_flags(const char *, const struct in6_addr *);
+
+int if_route6(const struct rt6 *rt, int);
+#define add_route6(rt) if_route6(rt, 1)
+#define change_route6(rt) if_route6(rt, 0)
+#define del_route6(rt) if_route6(rt, -1)
+#define del_src_route6(rt) if_route6(rt, -2);
+
#else
#define ipv6_init() -1
#define ipv6_free_ll_callbacks(a)
* SUCH DAMAGE.
*/
+#include <sys/param.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
int if_conf(struct interface *);
int if_init(struct interface *);
-int if_address6(const struct ipv6_addr *, int);
-#define add_address6(a) if_address6(a, 1)
-#define del_address6(a) if_address6(a, -1)
-int in6_addr_flags(const char *, const struct in6_addr *);
-
-int if_route6(const struct rt6 *rt, int);
-#define add_route6(rt) if_route6(rt, 1)
-#define change_route6(rt) if_route6(rt, 0)
-#define del_route6(rt) if_route6(rt, -1)
-#define del_src_route6(rt) if_route6(rt, -2);
-int pfx_flush(void);
-
int open_link_socket(void);
int manage_link(int);
int carrier_status(struct interface *);
* SUCH DAMAGE.
*/
+#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/utsname.h>
+
+#include <net/if.h>
#include <netinet/in.h>
+#include <netinet6/in6_var.h>
#include <errno.h>
#include <stdlib.h>
+#include <string.h>
#include <syslog.h>
#include "dhcpcd.h"
return march;
}
+#ifdef INET6
#define get_inet6_sysctl(code) inet6_sysctl(code, 0, 0)
#define set_inet6_sysctl(code, val) inet6_sysctl(code, val, 1)
static int
syslog(LOG_ERR, "IPV6CTL_ACCEPT_RTADV: %m");
}
+static int
+ipv6_ra_flush(void)
+{
+ int s;
+ char dummy[IFNAMSIZ + 8];
+
+ s = socket(AF_INET6, SOCK_DGRAM, 0);
+ if (s == -1)
+ return -1;
+ strcpy(dummy, "lo0");
+ if (ioctl(s, SIOCSRTRFLUSH_IN6, (caddr_t)&dummy) == -1)
+ syslog(LOG_ERR, "SIOSRTRFLUSH_IN6: %m");
+ if (ioctl(s, SIOCSPFXFLUSH_IN6, (caddr_t)&dummy) == -1)
+ syslog(LOG_ERR, "SIOSPFXFLUSH_IN6: %m");
+ close(s);
+ return 0;
+}
+
int
check_ipv6(const char *ifname)
{
return 0;
}
+ ipv6_ra_flush();
+
return 1;
}
r = get_inet6_sysctl(IPV6CTL_DAD_COUNT);
return r < 0 ? 0 : r;
}
+#endif
#endif
;
-char **restore;
-ssize_t nrestore;
+#ifdef INET6
+static char **restore;
+static ssize_t nrestore;
+#endif
char *
hardware_platform(void)
return p;
}
+#ifdef INET6
static int
check_proc_int(const char *path)
{
r = check_proc_int(path);
return r < 0 ? 0 : r;
}
+#endif
#define PLATFORM_H
char *hardware_platform(void);
+#ifdef INET6
int check_ipv6(const char *);
int ipv6_dadtransmits(const char *);
+#else
+#define check_ipv6(a) 0
+#endif
#endif