#include "config.h"
#include "common.h"
#include "configure.h"
+#include "dhcp.h"
#include "if-options.h"
#include "if-pref.h"
#include "net.h"
}
static struct rt *
-get_routes(const struct interface *iface) {
+get_routes(const struct interface *iface)
+{
struct rt *rt, *nrt = NULL, *r = NULL;
if (iface->state->options->routes != NULL) {
return get_option_routes(iface->state->new);
}
+static struct rt *
+add_destination_route(struct rt *rt, const struct interface *iface)
+{
+ struct rt *r;
+
+ if (!(iface->flags & IFF_POINTOPOINT) ||
+ !has_option_mask(iface->state->options->dstmask, DHO_ROUTER))
+ return rt;
+ r = xmalloc(sizeof(*r));
+ r->dest.s_addr = INADDR_ANY;
+ r->net.s_addr = INADDR_ANY;
+ r->gate.s_addr = iface->dst.s_addr;
+ r->next = rt;
+ return r;
+}
+
void
build_routes(void)
{
continue;
dnr = get_routes(ifp);
dnr = add_subnet_route(dnr, ifp);
+ dnr = add_destination_route(dnr, ifp);
for (rt = dnr; rt && (rtn = rt->next, 1); lrt = rt, rt = rtn) {
rt->iface = ifp;
/* Is this route already in our table? */
{
struct dhcp_message *dhcp = iface->state->new;
struct dhcp_lease *lease = &iface->state->lease;
+ struct if_options *ifo = iface->state->options;
struct rt *rt;
/* As we are now adjusting an interface, we need to ensure
}
/* This also changes netmask */
- if (!(iface->state->options->options & DHCPCD_INFORM) ||
+ if (!(ifo->options & DHCPCD_INFORM) ||
!has_address(iface->name, &lease->addr, &lease->net))
{
syslog(LOG_DEBUG, "%s: adding IP address %s/%d",
build_routes();
if (!iface->state->lease.frominfo &&
- !(iface->state->options->options & DHCPCD_INFORM))
+ !(ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC)))
if (write_lease(iface, dhcp) == -1)
syslog(LOG_ERR, "write_lease: %m");
run_script(iface);
memcpy(p, &_val.s_addr, 4); \
p += 4; \
}
+
+int
+dhcp_message_add_addr(struct dhcp_message *dhcp,
+ uint8_t type, struct in_addr addr)
+{
+ uint8_t *p;
+ size_t len;
+
+ p = dhcp->options;
+ while (*p != DHO_END) {
+ p++;
+ p += *p + 1;
+ }
+
+ len = p - (uint8_t *)dhcp;
+ if (len + 6 > sizeof(*dhcp)) {
+ errno = ENOMEM;
+ return -1;
+ }
+
+ PUTADDR(type, addr);
+ *p = DHO_END;
+ return 0;
+}
+
ssize_t
make_message(struct dhcp_message **message,
const struct interface *iface,
ssize_t configure_env(char **, const char *, const struct dhcp_message *,
const struct if_options *);
+int dhcp_message_add_addr(struct dhcp_message *, uint8_t, struct in_addr);
ssize_t make_message(struct dhcp_message **, const struct interface *,
uint8_t);
int valid_dhcp_packet(unsigned char *);
continue;
}
if (iface->flags & IFF_POINTOPOINT &&
- iface->state->lease.server.s_addr != from.s_addr)
+ iface->dst.s_addr != from.s_addr)
{
syslog(LOG_WARNING,
"%s: server %s is not destination",
free_options(ifs->options);
ifo = ifs->options = read_config(cffile, iface->name, iface->ssid);
add_options(ifo, argc, argv);
- if (iface->flags & IFF_NOARP)
- ifo->options &= ~(DHCPCD_ARP | DHCPCD_IPV4LL);
if (iface->flags & IFF_POINTOPOINT && !(ifo->options & DHCPCD_INFORM))
ifo->options |= DHCPCD_STATIC;
+ if (iface->flags & IFF_NOARP ||
+ ifo->options & (DHCPCD_INFORM | DHCPCD_STATIC))
+ ifo->options &= ~(DHCPCD_ARP | DHCPCD_IPV4LL);
if (ifo->options & DHCPCD_LINK && carrier_status(iface->name) == -1)
ifo->options &= ~DHCPCD_LINK;
}
}
-static int
-dhcp_message_add_addr(struct dhcp_message *dhcp, char c, struct in_addr *addr)
-{
- uint8_t *p;
- size_t len;
-
- p = dhcp->options;
- while (*p != DHO_END) {
- p++;
- p += *p + 1;
- }
-
- len = p - (uint8_t *)dhcp;
- if (len + 6 > sizeof(*dhcp)) {
- errno = ENOMEM;
- return -1;
- }
-
- *p++ = c;
- *p++ = sizeof(addr->s_addr);
- memcpy(p, &addr->s_addr, sizeof(addr->s_addr));
- p += sizeof(addr->s_addr);
- *p = DHO_END;
- return 0;
-}
-
void
handle_ifa(int type, const char *ifname,
struct in_addr *addr, struct in_addr *net, struct in_addr *dst)
free(ifp->state->old);
ifp->state->old = ifp->state->new;
ifp->state->new = dhcp_message_new(addr, net);
+ ifp->dst.s_addr = dst ? dst->s_addr : INADDR_ANY;
if (dst) {
for (i = 1; i < 255; i++)
- if (has_option_mask(ifo->dstmask, i))
+ if (i != DHO_ROUTER &&
+ has_option_mask(ifo->dstmask, i))
dhcp_message_add_addr(
ifp->state->new,
- i, dst);
+ i, *dst);
}
ifp->state->reason = "STATIC";
build_routes();
if (ifo->options & DHCPCD_INFORM) {
ifp->state->state = DHS_INFORM;
ifp->state->xid = arc4random();
+ ifp->state->lease.server.s_addr =
+ dst ? dst->s_addr : INADDR_ANY;
ifp->addr = *addr;
ifp->net = *net;
- ifp->state->lease.server = *dst;
open_sockets(ifp);
send_inform(ifp);
}
struct in_addr addr;
struct in_addr net;
+ struct in_addr dst;
char leasefile[PATH_MAX];
time_t start_uptime;