Ensure that if.c and if-KERNEL.c are namespaced correctly.
PROG= dhcpcd
SRCS= common.c control.c dhcpcd.c duid.c eloop.c
-SRCS+= if-options.c if-pref.c net.c script.c
+SRCS+= if.c if-options.c if-pref.c script.c
SRCS+= dhcp-common.c
CFLAGS?= -O2
* SUCH DAMAGE.
*/
+#include <netinet/if_ether.h>
+
#include <errno.h>
#include <signal.h>
#include <stdlib.h>
#include "dhcp.h"
#include "dhcpcd.h"
#include "eloop.h"
+#include "if.h"
#include "if-options.h"
#include "ipv4ll.h"
-#include "net.h"
#define ARP_LEN \
(sizeof(struct arphdr) + (2 * sizeof(uint32_t)) + (2 * HWADDR_LEN))
APPEND(&sip, sizeof(sip));
ZERO(ifp->hwlen);
APPEND(&tip, sizeof(tip));
- return ipv4_sendrawpacket(ifp, ETHERTYPE_ARP, arp_buffer, len);
+ return if_sendrawpacket(ifp, ETHERTYPE_ARP, arp_buffer, len);
eexit:
errno = ENOBUFS;
state = D_STATE(ifp);
state->fail.s_addr = 0;
for(;;) {
- bytes = ipv4_getrawpacket(ifp, ETHERTYPE_ARP,
+ bytes = if_readrawpacket(ifp, ETHERTYPE_ARP,
arp_buffer, sizeof(arp_buffer), NULL);
if (bytes == 0 || bytes == -1)
return;
if (state->new == NULL)
return;
if (state->arp_fd == -1) {
- state->arp_fd = ipv4_opensocket(ifp, ETHERTYPE_ARP);
+ state->arp_fd = if_openrawsocket(ifp, ETHERTYPE_ARP);
if (state->arp_fd == -1) {
syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
return;
int arping = 0;
if (state->arp_fd == -1) {
- state->arp_fd = ipv4_opensocket(ifp, ETHERTYPE_ARP);
+ state->arp_fd = if_openrawsocket(ifp, ETHERTYPE_ARP);
if (state->arp_fd == -1) {
syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
return;
#include <sys/param.h>
#include <sys/time.h>
+#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
return tv.tv_sec;
}
+char *
+hwaddr_ntoa(const unsigned char *hwaddr, size_t hwlen, char *buf, size_t buflen)
+{
+ char *p;
+ size_t i;
+
+ if (buf == NULL) {
+ return NULL;
+ }
+
+ if (hwlen * 3 > buflen) {
+ errno = ENOBUFS;
+ return 0;
+ }
+
+ p = buf;
+ for (i = 0; i < hwlen; i++) {
+ if (i > 0)
+ *p ++= ':';
+ p += snprintf(p, 3, "%.2x", hwaddr[i]);
+ }
+ *p ++= '\0';
+ return buf;
+}
+
+size_t
+hwaddr_aton(unsigned char *buffer, const char *addr)
+{
+ char c[3];
+ const char *p = addr;
+ unsigned char *bp = buffer;
+ size_t len = 0;
+
+ c[2] = '\0';
+ while (*p) {
+ c[0] = *p++;
+ c[1] = *p++;
+ /* Ensure that digits are hex */
+ if (isxdigit((unsigned char)c[0]) == 0 ||
+ isxdigit((unsigned char)c[1]) == 0)
+ {
+ errno = EINVAL;
+ return 0;
+ }
+ /* We should have at least two entries 00:01 */
+ if (len == 0 && *p == '\0') {
+ errno = EINVAL;
+ return 0;
+ }
+ /* Ensure that next data is EOL or a seperator with data */
+ if (!(*p == '\0' || (*p == ':' && *(p + 1) != '\0'))) {
+ errno = EINVAL;
+ return 0;
+ }
+ if (*p)
+ p++;
+ if (bp)
+ *bp++ = (unsigned char)strtol(c, NULL, 16);
+ len++;
+ }
+ return len;
+}
ssize_t setvard(char ***, const char *, const char *, size_t);
time_t uptime(void);
+char *hwaddr_ntoa(const unsigned char *, size_t, char *, size_t);
+size_t hwaddr_aton(unsigned char *, const char *);
#endif
#include "common.h"
#include "dhcp-common.h"
#include "dhcp.h"
-#include "platform.h"
+#include "if.h"
+#include "ipv6.h"
struct dhcp_opt *
vivso_find(uint32_t iana_en, const void *arg)
utn.sysname, utn.release, utn.machine);
p += l;
len -= (size_t)l;
- l = hardware_platform(p, len);
+ l = if_machinearch(p, len);
return (size_t)(p - str);
}
#include <arpa/inet.h>
#include <net/route.h>
+#include <netinet/if_ether.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include "dhcp-common.h"
#include "duid.h"
#include "eloop.h"
+#include "if.h"
#include "ipv4.h"
#include "ipv4ll.h"
#include "script.h"
*p++ = DHO_MAXMESSAGESIZE;
*p++ = 2;
- mtu = get_mtu(iface->name);
+ mtu = if_getmtu(iface->name);
if (mtu < MTU_MIN) {
- if (set_mtu(iface->name, MTU_MIN) == 0)
+ if (if_setmtu(iface->name, MTU_MIN) == 0)
sz = MTU_MIN;
} else if (mtu > MTU_MAX) {
/* Even though our MTU could be greater than
if (udp == NULL) {
syslog(LOG_ERR, "dhcp_makeudppacket: %m");
} else {
- r = ipv4_sendrawpacket(iface, ETHERTYPE_IP,
+ r = if_sendrawpacket(iface, ETHERTYPE_IP,
(uint8_t *)udp, ulen);
free(udp);
}
* As such we remove it from consideration without actually
* stopping the interface. */
if (r == -1) {
- syslog(LOG_ERR, "%s: ipv4_sendrawpacket: %m",
+ syslog(LOG_ERR, "%s: if_sendrawpacket: %m",
iface->name);
if (!(iface->ctx->options & DHCPCD_TEST))
dhcp_drop(iface, "FAIL");
* The benefit is that if we get >1 DHCP packet in our buffer and
* the first one fails for any reason, we can use the next. */
for(;;) {
- bytes = (size_t)ipv4_getrawpacket(iface, ETHERTYPE_IP,
+ bytes = (size_t)if_readrawpacket(iface, ETHERTYPE_IP,
iface->ctx->packet, udp_dhcp_len, &partialcsum);
if (bytes == 0 || (ssize_t)bytes == -1)
break;
state = D_STATE(ifp);
if (state->raw_fd == -1) {
- state->raw_fd = ipv4_opensocket(ifp, ETHERTYPE_IP);
+ state->raw_fd = if_openrawsocket(ifp, ETHERTYPE_IP);
if (state->raw_fd == -1) {
syslog(LOG_ERR, "%s: %s: %m", __func__, ifp->name);
return -1;
#include "dhcpcd.h"
#include "if-options.h"
-#include "net.h"
#ifdef INET
char *decode_rfc3361(const uint8_t *, size_t);
#include "duid.h"
#include "eloop.h"
#include "ipv6nd.h"
-#include "platform.h"
#include "script.h"
#ifndef __UNCONST
#include "dhcp6.h"
#include "duid.h"
#include "eloop.h"
+#include "if.h"
#include "if-options.h"
#include "if-pref.h"
#include "ipv4.h"
#include "ipv6.h"
#include "ipv6nd.h"
-#include "net.h"
-#include "platform.h"
#include "script.h"
#ifdef USE_SIGNALS
eloop_timeout_delete(ctx->eloop, NULL, ifp);
if (ifp->options->options & DHCPCD_DEPARTED)
script_runreason(ifp, "DEPARTED");
- free_interface(ifp);
+ if_free(ifp);
if (!(ctx->options & (DHCPCD_MASTER | DHCPCD_TEST)))
eloop_exit(ctx->eloop, EXIT_FAILURE);
}
ifo->options &= ~(DHCPCD_ARP | DHCPCD_IPV4LL);
if (!(ifp->flags & (IFF_POINTOPOINT | IFF_LOOPBACK | IFF_MULTICAST)))
ifo->options &= ~DHCPCD_IPV6RS;
- if (ifo->options & DHCPCD_LINK && carrier_status(ifp) == LINK_UNKNOWN)
+ if (ifo->options & DHCPCD_LINK && if_carrier(ifp) == LINK_UNKNOWN)
ifo->options &= ~DHCPCD_LINK;
if (ifo->metric != -1)
/* We want to disable kernel interface RA as early as possible. */
if (ifo->options & DHCPCD_IPV6RS) {
- ra_global = check_ipv6(ifp->ctx, NULL,
+ ra_global = if_checkipv6(ifp->ctx, NULL,
ifp->ctx->options & DHCPCD_IPV6RA_OWN ? 1 : 0);
- ra_iface = check_ipv6(ifp->ctx, ifp->name,
+ ra_iface = if_checkipv6(ifp->ctx, ifp->name,
ifp->options->options & DHCPCD_IPV6RA_OWN ? 1 : 0);
if (ra_global == -1 || ra_iface == -1)
ifo->options &= ~DHCPCD_IPV6RS;
return;
if (carrier == LINK_UNKNOWN)
- carrier = carrier_status(ifp); /* will set ifp->flags */
+ carrier = if_carrier(ifp); /* will set ifp->flags */
else
ifp->flags = flags;
handle_interface(ctx, 0, ifp->name);
#endif
if (ifp->wireless)
- getifssid(ifp->name, ifp->ssid);
+ if_getssid(ifp->name, ifp->ssid);
configure_interface(ifp, ctx->argc, ctx->argv);
script_runreason(ifp, "CARRIER");
start_interface(ifp);
struct dhcpcd_ctx *ctx;
ctx = arg;
- if (manage_link(ctx) == -1 && errno != ENXIO && errno != ENODEV)
- syslog(LOG_ERR, "manage_link: %m");
+ if (if_managelink(ctx) == -1 && errno != ENXIO && errno != ENODEV)
+ syslog(LOG_ERR, "if_managelink: %m");
}
static void
reason = NULL; /* appease gcc */
if (ifo->options & DHCPCD_LINK) {
- switch (carrier_status(ifp)) {
+ switch (if_carrier(ifp)) {
case LINK_DOWN:
ifp->carrier = LINK_DOWN;
reason = "NOCARRIER";
return;
}
- ifs = discover_interfaces(ctx, -1, UNCONST(argv));
+ ifs = if_discover(ctx, -1, UNCONST(argv));
TAILQ_FOREACH_SAFE(ifp, ifs, next, ifn) {
if (strcmp(ifp->name, ifname) != 0)
continue;
/* Free our discovered list */
while ((ifp = TAILQ_FIRST(ifs))) {
TAILQ_REMOVE(ifs, ifp, next);
- free_interface(ifp);
+ if_free(ifp);
}
free(ifs);
}
struct if_head *ifs;
struct interface *ifn, *ifp;
- ifs = discover_interfaces(ctx, argc - oi, argv + oi);
+ ifs = if_discover(ctx, argc - oi, argv + oi);
if (ifs == NULL)
return;
if_reboot(ifn, argc, argv);
else
ipv4_applyaddr(ifn);
- free_interface(ifp);
+ if_free(ifp);
} else {
init_state(ifp, argc, argv);
TAILQ_INSERT_TAIL(ctx->ifaces, ifp, next);
* instead.
* We also need to open this before checking for interfaces below
* so that we pickup any new addresses during the discover phase. */
- ctx.link_fd = open_link_socket();
+ ctx.link_fd = if_openlinksocket();
if (ctx.link_fd == -1)
syslog(LOG_ERR, "open_link_socket: %m");
else
(DHCPCD_MASTER | DHCPCD_DEV))
dev_start(&ctx);
- ctx.ifaces = discover_interfaces(&ctx, ctx.ifc, ctx.ifv);
+ ctx.ifaces = if_discover(&ctx, ctx.ifc, ctx.ifv);
for (i = 0; i < ctx.ifc; i++) {
if (find_interface(&ctx, ctx.ifv[i]) == NULL)
syslog(LOG_ERR, "%s: interface not found or invalid",
if (ctx.ifaces) {
while ((ifp = TAILQ_FIRST(ctx.ifaces))) {
TAILQ_REMOVE(ctx.ifaces, ifp, next);
- free_interface(ifp);
+ if_free(ifp);
}
free(ctx.ifaces);
}
free_options(ifo);
free_globals(&ctx);
- restore_kernel_ra(&ctx);
+ if_rarestore(&ctx);
ipv4_ctxfree(&ctx);
ipv6_ctxfree(&ctx);
dev_stop(&ctx, !(ctx.options & DHCPCD_FORKED));
#endif
#include "common.h"
+#include "dhcpcd.h"
#include "duid.h"
-#include "net.h"
static size_t
duid_make(unsigned char *d, const struct interface *ifp, uint16_t type)
#ifndef DUID_H
#define DUID_H
-#include "net.h"
-
-#ifndef DUID_LEN
-# define DUID_LEN 128 + 2
-#endif
+#define DUID_LEN 128 + 2
size_t duid_init(const struct interface *);
#ifdef __FreeBSD__ /* Needed so that including netinet6/in6_var.h works */
# include <net/if_var.h>
#endif
+#include <net/if_ether.h>
#include <net/if_media.h>
#include <net/route.h>
#include <netinet/in.h>
#include "config.h"
#include "common.h"
#include "dhcp.h"
+#include "if.h"
#include "if-options.h"
#include "ipv4.h"
#include "ipv6.h"
-#include "platform.h"
#include "bpf-filter.h"
}
int
-open_link_socket(void)
+if_openlinksocket(void)
{
#ifdef SOCK_CLOEXEC
}
int
-getifssid(const char *ifname, char *ssid)
+if_getssid(const char *ifname, char *ssid)
{
int s, retval = -1;
#if defined(SIOCG80211NWID)
if (ifmr.ifm_status & IFM_AVALID &&
IFM_TYPE(ifmr.ifm_active) == IFM_IEEE80211)
{
- if (getifssid(ifname, NULL) == -1)
+ if (if_getssid(ifname, NULL) == -1)
return 1;
}
return 0;
#ifdef INET
int
-ipv4_opensocket(struct interface *ifp, int protocol)
+if_openrawsocket(struct interface *ifp, int protocol)
{
struct dhcp_state *state;
int fd = -1;
}
ssize_t
-ipv4_sendrawpacket(const struct interface *ifp, int protocol,
+if_sendrawpacket(const struct interface *ifp, int protocol,
const void *data, size_t len)
{
struct iovec iov[2];
/* BPF requires that we read the entire buffer.
* So we pass the buffer in the API so we can loop on >1 packet. */
ssize_t
-ipv4_getrawpacket(struct interface *ifp, int protocol,
+if_readrawpacket(struct interface *ifp, int protocol,
void *data, size_t len, int *partialcsum)
{
int fd = -1;
return bytes;
}
}
+
int
if_address(const struct interface *iface, const struct in_addr *address,
const struct in_addr *netmask, const struct in_addr *broadcast,
#ifdef INET6
int
-in6_addr_flags(const char *ifname, const struct in6_addr *addr)
+if_addrflags6(const char *ifname, const struct in6_addr *addr)
{
int s, flags;
struct in6_ifreq ifr6;
#endif
int
-manage_link(struct dhcpcd_ctx *ctx)
+if_managelink(struct dhcpcd_ctx *ctx)
{
/* route and ifwatchd like a msg buf size of 2048 */
char msg[2048], *p, *e, *cp, ifname[IF_NAMESIZE];
sin6->sin6_addr.s6_addr,
sizeof(ia6.s6_addr));
if (rtm->rtm_type == RTM_NEWADDR) {
- ifa_flags = in6_addr_flags(
+ ifa_flags = if_addrflags6(
ifname,
&ia6);
if (ifa_flags == -1)
# endif
#endif
int
-hardware_platform(char *str, size_t len)
+if_machinearch(char *str, size_t len)
{
int mib[2] = { CTL_HW, HW_MACHINE_ARCH };
char march[SYS_NMLN];
}
void
-restore_kernel_ra(struct dhcpcd_ctx *ctx)
+if_rarestore(struct dhcpcd_ctx *ctx)
{
if (ctx->options & DHCPCD_FORKED)
}
static int
-ipv6_ra_flush(void)
+if_raflush(void)
{
int s;
char dummy[IFNAMSIZ + 8];
}
int
-check_ipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
+if_checkipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
{
int ra;
/* Flush the kernel knowledge of advertised routers
* and prefixes so the kernel does not expire prefixes
* and default routes we are trying to own. */
- ipv6_ra_flush();
+ if_raflush();
}
ctx->ra_global = ra;
return ra;
}
-
-int
-ipv6_dadtransmits(__unused const char *ifname)
-{
- int r;
-
- r = get_inet6_sysctl(IPV6CTL_DAD_COUNT);
- return r < 0 ? 0 : r;
-}
#endif
/*
* dhcpcd - DHCP client daemon
- * Copyright (c) 2009-2013 Roy Marples <roy@marples.name>
+ * Copyright (c) 2009-2014 Roy Marples <roy@marples.name>
* All rights reserved
* Redistribution and use in source and binary forms, with or without
#include "common.h"
#include "config.h"
-/* We can't include net.h or dhcpcd.h because
+/* We can't include if.h or dhcpcd.h because
* they would pull in net/if.h, which defeats the purpose of this hack. */
#define IF_SSIDSIZE 33
-int getifssid(const char *ifname, char *ssid);
+int if_getssid(const char *ifname, char *ssid);
int
-getifssid(const char *ifname, char *ssid)
+if_getssid(const char *ifname, char *ssid)
{
#ifdef SIOCGIWESSID
int s, retval;
#include <arpa/inet.h>
#include <net/if.h>
+#include <net/if_ether.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <net/route.h>
#include "common.h"
#include "dev.h"
#include "dhcp.h"
+#include "if.h"
#include "ipv4.h"
#include "ipv6.h"
-#include "net.h"
-#include "platform.h"
#define bpf_insn sock_filter
#define BPF_SKIPTYPE
#define BPF_ETHCOOK -ETH_HLEN
#define BPF_WHOLEPACKET 0x0fffffff /* work around buggy LPF filters */
-#include "config.h"
-#include "common.h"
-#include "dhcp.h"
-#include "ipv4.h"
#include "bpf-filter.h"
/* Broadcast address for IPoIB */
;
int
-hardware_platform(char *str, size_t len)
+if_machinearch(char *str, size_t len)
{
FILE *fp;
char buf[256];
}
int
-open_link_socket(void)
+if_openlinksocket(void)
{
struct sockaddr_nl snl;
}
int
-manage_link(struct dhcpcd_ctx *ctx)
+if_managelink(struct dhcpcd_ctx *ctx)
{
return get_netlink(ctx, ctx->link_fd, MSG_DONTWAIT, &link_netlink);
#ifdef INET
int
-ipv4_opensocket(struct interface *ifp, int protocol)
+if_openrawsocket(struct interface *ifp, int protocol)
{
int s;
union sockunion {
}
ssize_t
-ipv4_sendrawpacket(const struct interface *ifp, int protocol,
+if_sendrawpacket(const struct interface *ifp, int protocol,
const void *data, size_t len)
{
const struct dhcp_state *state;
}
ssize_t
-ipv4_getrawpacket(struct interface *ifp, int protocol,
+if_readrawpacket(struct interface *ifp, int protocol,
void *data, size_t len, int *partialcsum)
{
struct iovec iov = {
}
int
-in6_addr_flags(const char *ifname, const struct in6_addr *addr)
+if_addrflags6(const char *ifname, const struct in6_addr *addr)
{
FILE *fp;
char *p, ifaddress[33], address[33], name[IF_NAMESIZE + 1];
static const char *prefix = "/proc/sys/net/ipv6/conf";
void
-restore_kernel_ra(struct dhcpcd_ctx *ctx)
+if_rarestore(struct dhcpcd_ctx *ctx)
{
char path[256];
}
int
-check_ipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
+if_checkipv6(struct dhcpcd_ctx *ctx, const char *ifname, int own)
{
int ra;
size_t i;
return ra;
}
-
-int
-ipv6_dadtransmits(const char *ifname)
-{
- char path[256];
- int r;
-
- if (ifname == NULL)
- ifname = "default";
-
- snprintf(path, sizeof(path), "%s/%s/dad_transmits", prefix, ifname);
- r = check_proc_int(path);
- return r < 0 ? 0 : r;
-}
#endif
#include "dhcpcd-embedded.h"
#include "if-options.h"
#include "ipv4.h"
-#include "platform.h"
/* These options only make sense in the config file, so don't use any
valid short options for them */
#ifdef INET6
ifo->options |= DHCPCD_IPV6 | DHCPCD_IPV6RS | DHCPCD_IPV6RA_REQRDNSS;
ifo->options |= DHCPCD_DHCP6;
- ifo->dadtransmits = ipv6_dadtransmits(ifname);
#endif
ifo->timeout = DEFAULT_TIMEOUT;
ifo->reboot = DEFAULT_REBOOT;
uint16_t ia_type;
struct if_ia *ia;
size_t ia_len;
-#ifdef INET6
- int dadtransmits;
-#endif
struct dhcp_opt *dhcp_override;
size_t dhcp_override_len;
#include "config.h"
#include "dhcp.h"
+#include "dhcpcd.h"
#include "if-pref.h"
-#include "net.h"
/* Interface comparer for working out ordering. */
static int
#include "dev.h"
#include "dhcp.h"
#include "dhcp6.h"
+#include "if.h"
#include "if-options.h"
#include "ipv4.h"
#include "ipv6nd.h"
-#include "net.h"
-
-char *
-hwaddr_ntoa(const unsigned char *hwaddr, size_t hwlen, char *buf, size_t buflen)
-{
- char *p;
- size_t i;
-
- if (buf == NULL) {
- return NULL;
- }
-
- if (hwlen * 3 > buflen) {
- errno = ENOBUFS;
- return 0;
- }
-
- p = buf;
- for (i = 0; i < hwlen; i++) {
- if (i > 0)
- *p ++= ':';
- p += snprintf(p, 3, "%.2x", hwaddr[i]);
- }
- *p ++= '\0';
- return buf;
-}
-
-size_t
-hwaddr_aton(unsigned char *buffer, const char *addr)
-{
- char c[3];
- const char *p = addr;
- unsigned char *bp = buffer;
- size_t len = 0;
-
- c[2] = '\0';
- while (*p) {
- c[0] = *p++;
- c[1] = *p++;
- /* Ensure that digits are hex */
- if (isxdigit((unsigned char)c[0]) == 0 ||
- isxdigit((unsigned char)c[1]) == 0)
- {
- errno = EINVAL;
- return 0;
- }
- /* We should have at least two entries 00:01 */
- if (len == 0 && *p == '\0') {
- errno = EINVAL;
- return 0;
- }
- /* Ensure that next data is EOL or a seperator with data */
- if (!(*p == '\0' || (*p == ':' && *(p + 1) != '\0'))) {
- errno = EINVAL;
- return 0;
- }
- if (*p)
- p++;
- if (bp)
- *bp++ = (unsigned char)strtol(c, NULL, 16);
- len++;
- }
- return len;
-}
void
-free_interface(struct interface *ifp)
+if_free(struct interface *ifp)
{
if (ifp == NULL)
}
int
-carrier_status(struct interface *iface)
+if_carrier(struct interface *iface)
{
int s, r;
struct ifreq ifr;
}
struct if_head *
-discover_interfaces(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
+if_discover(struct dhcpcd_ctx *ctx, int argc, char * const *argv)
{
struct ifaddrs *ifaddrs, *ifa;
char *p;
/* Bring the interface up if not already */
if (!(ifp->flags & IFF_UP)
#ifdef SIOCGIFMEDIA
- && carrier_status(ifp) != LINK_UNKNOWN
+ && if_carrier(ifp) != LINK_UNKNOWN
#endif
)
{
/* Don't allow loopback unless explicit */
if (ifp->flags & IFF_LOOPBACK) {
if (argc == 0 && ctx->ifac == 0) {
- free_interface(ifp);
+ if_free(ifp);
continue;
}
} else if (ifa->ifa_addr != NULL) {
if (ioctl(s_link, SIOCGLIFADDR, &iflr) == -1 ||
!(iflr.flags & IFLR_ACTIVE))
{
- free_interface(ifp);
+ if_free(ifp);
continue;
}
#endif
ifp->family != ARPHRD_ETHER)
{
if (argc == 0 && ctx->ifac == 0) {
- free_interface(ifp);
+ if_free(ifp);
continue;
}
switch (ifp->family) {
/* Handle any platform init for the interface */
if (if_init(ifp) == -1) {
syslog(LOG_ERR, "%s: if_init: %m", p);
- free_interface(ifp);
+ if_free(ifp);
continue;
}
/* Ensure that the MTU is big enough for DHCP */
- if (get_mtu(ifp->name) < MTU_MIN &&
- set_mtu(ifp->name, MTU_MIN) == -1)
+ if (if_getmtu(ifp->name) < MTU_MIN &&
+ if_setmtu(ifp->name, MTU_MIN) == -1)
{
syslog(LOG_ERR, "%s: set_mtu: %m", p);
- free_interface(ifp);
+ if_free(ifp);
continue;
}
/* We reserve the 100 range for virtual interfaces, if and when
* we can work them out. */
ifp->metric = 200 + ifp->index;
- if (getifssid(ifp->name, ifp->ssid) != -1) {
+ if (if_getssid(ifp->name, ifp->ssid) != -1) {
ifp->wireless = 1;
ifp->metric += 100;
}
case AF_INET6:
sin6 = (const struct sockaddr_in6 *)
(void *)ifa->ifa_addr;
- ifa_flags = in6_addr_flags(ifa->ifa_name,
+ ifa_flags = if_addrflags6(ifa->ifa_name,
&sin6->sin6_addr);
if (ifa_flags != -1)
ipv6_handleifa(ctx, RTM_NEWADDR, ifs,
}
int
-do_mtu(const char *ifname, short int mtu)
+if_domtu(const char *ifname, short int mtu)
{
int s, r;
struct ifreq ifr;
#include <net/if.h>
#include <netinet/in.h>
-#include <netinet/if_ether.h>
#include "config.h"
-#include "dhcp.h"
#include "dhcpcd.h"
+#include "ipv4.h"
#include "ipv6.h"
/* Some systems have route metrics */
# define IN_LINKLOCAL(addr) ((addr & IN_CLASSB_NET) == LINKLOCAL_ADDR)
#endif
-char *hwaddr_ntoa(const unsigned char *, size_t, char *, size_t);
-size_t hwaddr_aton(unsigned char *, const char *);
-
-int getifssid(const char *, char *);
-int if_vimaster(const char *);
-struct if_head *discover_interfaces(struct dhcpcd_ctx *, int, char * const *);
-void free_interface(struct interface *);
-int do_mtu(const char *, short int);
-#define get_mtu(iface) do_mtu(iface, 0)
-#define set_mtu(iface, mtu) do_mtu(iface, mtu)
+struct if_head *if_discover(struct dhcpcd_ctx *, int, char * const *);
+void if_free(struct interface *);
+int if_domtu(const char *, short int);
+#define if_getmtu(iface) if_domtu(iface, 0)
+#define if_setmtu(iface, mtu) if_domtu(iface, mtu)
+int if_carrier(struct interface *);
+/* The below functions are provided by if-KERNEL.c */
int if_conf(struct interface *);
int if_init(struct interface *);
+int if_getssid(const char *, char *);
+int if_vimaster(const char *);
+int if_openlinksocket(void);
+int if_managelink(struct dhcpcd_ctx *);
+
+#ifdef INET
+int if_openrawsocket(struct interface *, int);
+ssize_t if_sendrawpacket(const struct interface *,
+ int, const void *, size_t);
+ssize_t if_readrawpacket(struct interface *, int, void *, size_t, int *);
+
+int if_address(const struct interface *,
+ const struct in_addr *, const struct in_addr *,
+ const struct in_addr *, int);
+#define if_addaddress(iface, addr, net, brd) \
+ if_address(iface, addr, net, brd, 1)
+#define if_setaddress(iface, addr, net, brd) \
+ if_address(iface, addr, net, brd, 2)
+#define if_deladdress(iface, addr, net) \
+ if_address(iface, addr, net, NULL, -1)
+
+int if_route(const struct rt *rt, int);
+#define if_addroute(rt) if_route(rt, 1)
+#define if_chgroute(rt) if_route(rt, 0)
+#define if_delroute(rt) if_route(rt, -1)
+#endif
+
+#ifdef INET6
+int if_checkipv6(struct dhcpcd_ctx *ctx, const char *, int);
+void if_rarestore(struct dhcpcd_ctx *);
+
+int if_address6(const struct ipv6_addr *, int);
+#define if_addaddress6(a) if_address6(a, 1)
+#define if_deladdress6(a) if_address6(a, -1)
+int if_addrflags6(const char *, const struct in6_addr *);
+
+int if_route6(const struct rt6 *rt, int);
+#define if_addroute6(rt) if_route6(rt, 1)
+#define if_chgroute6(rt) if_route6(rt, 0)
+#define if_delroute6(rt) if_route6(rt, -1)
+#else
+#define if_checkipv6(a, b, c) (-1)
+#define if_rarestore(a)
+#endif
-int open_link_socket(void);
-int manage_link(struct dhcpcd_ctx *);
-int carrier_status(struct interface *);
+int if_machinearch(char *, size_t);
#endif
#include "common.h"
#include "dhcpcd.h"
#include "dhcp.h"
+#include "if.h"
#include "if-options.h"
#include "if-pref.h"
#include "ipv4.h"
-#include "net.h"
#include "script.h"
#define IPV4_LOOPBACK_ROUTE
* prefer the interface.
* This also has the nice side effect of flushing ARP entries so
* we don't have to do that manually. */
- if (ipv4_deleteroute(ort) == -1 && errno != ESRCH)
- syslog(LOG_ERR, "%s: ipv4_deleteroute: %m", ort->iface->name);
- if (!ipv4_addroute(nrt))
+ if (if_delroute(ort) == -1 && errno != ESRCH)
+ syslog(LOG_ERR, "%s: ipv4_delroute: %m", ort->iface->name);
+ if (!if_addroute(nrt))
return 0;
- syslog(LOG_ERR, "%s: ipv4_addroute: %m", nrt->iface->name);
+ syslog(LOG_ERR, "%s: if_addroute: %m", nrt->iface->name);
return -1;
}
int retval;
desc_route("deleting", rt);
- retval = ipv4_deleteroute(rt);
+ retval = if_delroute(rt);
if (retval != 0 && errno != ENOENT && errno != ESRCH)
- syslog(LOG_ERR,"%s: ipv4_deleteroute: %m", rt->iface->name);
+ syslog(LOG_ERR,"%s: if_delroute: %m", rt->iface->name);
return retval;
}
syslog(LOG_DEBUG, "%s: deleting IP address %s/%d",
ifp->name, inet_ntoa(*addr), inet_ntocidr(*net));
- r = ipv4_deleteaddress(ifp, addr, net);
+ r = if_deladdress(ifp, addr, net);
if (r == -1 && errno != EADDRNOTAVAIL && errno != ENXIO &&
errno != ENODEV)
syslog(LOG_ERR, "%s: %s: %m", ifp->name, __func__);
ifp->name, inet_ntoa(lease->addr),
inet_ntocidr(lease->net));
if (ifo->options & DHCPCD_NOALIAS)
- r = ipv4_setaddress(ifp,
+ r = if_setaddress(ifp,
&lease->addr, &lease->net, &lease->brd);
else
- r = ipv4_addaddress(ifp,
+ r = if_addaddress(ifp,
&lease->addr, &lease->net, &lease->brd);
if (r == -1 && errno != EEXIST) {
- syslog(LOG_ERR, "%s: ipv4_addaddress: %m", __func__);
+ syslog(LOG_ERR, "%s: if_addaddress: %m", __func__);
return;
}
istate = ipv4_getstate(ifp);
rt->iface = ifp;
rt->metric = 0;
if (!find_route(ifp->ctx->ipv4_routes, rt, NULL))
- ipv4_deleteroute(rt);
+ if_delroute(rt);
free(rt);
}
void ipv4_handleifa(struct dhcpcd_ctx *, int, struct if_head *, const char *,
const struct in_addr *, const struct in_addr *, const struct in_addr *);
-int if_address(const struct interface *,
- const struct in_addr *, const struct in_addr *,
- const struct in_addr *, int);
-#define ipv4_addaddress(iface, addr, net, brd) \
- if_address(iface, addr, net, brd, 1)
-#define ipv4_setaddress(iface, addr, net, brd) \
- if_address(iface, addr, net, brd, 2)
-#define ipv4_deleteaddress(iface, addr, net) \
- if_address(iface, addr, net, NULL, -1)
-
-int if_route(const struct rt *rt, int);
-#define ipv4_addroute(rt) if_route(rt, 1)
-#define ipv4_changeroute(rt) if_route(rt, 0)
-#define ipv4_deleteroute(rt) if_route(rt, -1)
-#define del_src_route(rt) i_route(rt, -2);
void ipv4_freeroutes(struct rt_head *);
-int ipv4_opensocket(struct interface *, int);
-ssize_t ipv4_sendrawpacket(const struct interface *,
- int, const void *, size_t);
-ssize_t ipv4_getrawpacket(struct interface *, int, void *, size_t, int *);
void ipv4_free(struct interface *);
void ipv4_ctxfree(struct dhcpcd_ctx *);
#else
#include "common.h"
#include "dhcp.h"
#include "eloop.h"
+#include "if.h"
#include "if-options.h"
#include "ipv4ll.h"
-#include "net.h"
static struct dhcp_message *
ipv4ll_make_lease(uint32_t addr)
#include "dhcpcd.h"
#include "dhcp6.h"
#include "eloop.h"
+#include "if.h"
#include "ipv6.h"
#include "ipv6nd.h"
if (!(ap->flags & IPV6_AF_DADCOMPLETED) &&
ipv6_findaddr(ap->iface, &ap->addr))
ap->flags |= IPV6_AF_DADCOMPLETED;
- if (add_address6(ap) == -1) {
- syslog(LOG_ERR, "add_address6 %m");
+ if (if_addaddress6(ap) == -1) {
+ syslog(LOG_ERR, "if_addaddress6: %m");
return -1;
}
ap->flags &= ~IPV6_AF_NEW;
ap->flags |= IPV6_AF_DELEGATED;
if (ap->iface->options->options & DHCPCD_IPV6RA_OWN &&
ipv6_removesubnet(ap->iface, ap) == -1)
- syslog(LOG_ERR,"ipv6_removesubnet %m");
+ syslog(LOG_ERR,"ipv6_removesubnet: %m");
if (ap->prefix_pltime == ND6_INFINITE_LIFETIME &&
ap->prefix_vltime == ND6_INFINITE_LIFETIME)
syslog(LOG_DEBUG,
ap->iface->name, ap->saddr);
i++;
if (!IN6_IS_ADDR_UNSPECIFIED(&ap->addr) &&
- del_address6(ap) == -1 &&
+ if_deladdress6(ap) == -1 &&
errno != EADDRNOTAVAIL && errno != ENXIO)
- syslog(LOG_ERR, "del_address6 %m");
+ syslog(LOG_ERR, "if_deladdress6: %m");
}
eloop_q_timeout_delete(ap->iface->ctx->eloop,
0, NULL, ap);
{
syslog(LOG_INFO, "%s: deleting address %s",
ap->iface->name, ap->saddr);
- if (del_address6(ap) == -1 &&
+ if (if_deladdress6(ap) == -1 &&
errno != EADDRNOTAVAIL && errno != ENXIO)
- syslog(LOG_ERR, "del_address6 %m");
+ syslog(LOG_ERR, "if_deladdress6: :%m");
}
free(ap);
}
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) == -1 && errno != ESRCH)
- syslog(LOG_ERR, "%s: del_route6: %m", ort->iface->name);
- if (add_route6(nrt) == 0)
+ if (if_delroute6(ort) == -1 && errno != ESRCH)
+ syslog(LOG_ERR, "%s: if_delroute6: %m", ort->iface->name);
+ if (if_addroute6(nrt) == 0)
return 0;
- syslog(LOG_ERR, "%s: add_route6: %m", nrt->iface->name);
+ syslog(LOG_ERR, "%s: if_addroute6: %m", nrt->iface->name);
return -1;
}
int retval;
desc_route("deleting", rt);
- retval = del_route6(rt);
+ retval = if_delroute6(rt);
if (retval != 0 && errno != ENOENT && errno != ESRCH)
- syslog(LOG_ERR,"%s: del_route6: %m", rt->iface->name);
+ syslog(LOG_ERR,"%s: if_delroute6: %m", rt->iface->name);
return retval;
}
if (!find_route6(ifp->ctx->ipv6->routes, rt))
#endif
{
- r = del_route6(rt);
+ r = if_delroute6(rt);
if (r == -1 && errno == ESRCH)
r = 0;
}
int ipv6_removesubnet(struct interface *, struct ipv6_addr *);
void ipv6_buildroutes(struct dhcpcd_ctx *);
-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(a) NULL
#define ipv6_free_ll_callbacks(a)
+++ /dev/null
-/*
- * dhcpcd - DHCP client daemon
- * Copyright (c) 2006-2014 Roy Marples <roy@marples.name>
- * 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.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
- */
-
-#ifndef PLATFORM_H
-#define PLATFORM_H
-
-int hardware_platform(char *, size_t);
-#ifdef INET6
-int check_ipv6(struct dhcpcd_ctx *ctx, const char *, int);
-int ipv6_dadtransmits(const char *);
-void restore_kernel_ra(struct dhcpcd_ctx *);
-#else
-#define check_ipv6(a, b,c ) -1
-#define restore_kernel_ra(a)
-#endif
-
-#endif
#include "common.h"
#include "dhcp.h"
#include "dhcp6.h"
+#include "if.h"
#include "if-options.h"
#include "if-pref.h"
#include "ipv6nd.h"
-#include "net.h"
#include "script.h"
#ifdef HAVE_SPAWN_H
EMALLOC(6, e);
snprintf(env[6], e, "ifflags=%u", ifp->flags);
EMALLOC(7, e);
- snprintf(env[7], e, "ifmtu=%d", get_mtu(ifp->name));
+ snprintf(env[7], e, "ifmtu=%d", if_getmtu(ifp->name));
l = e = strlen("interface_order=");
TAILQ_FOREACH(ifp2, ifp->ctx->ifaces, next) {
e += strlen(ifp2->name) + 1;
#ifndef SCRIPT_H
#define SCRIPT_H
-#include "net.h"
-
void if_printoptions(void);
int send_interface(int, const struct interface *);
int script_runreason(const struct interface *, const char *);