summaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2012-11-08 21:32:56 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2012-11-08 21:32:56 +0000
commita10f0fb87cf2a387fb9baadde502dbd3b14ee038 (patch)
treed4dc9f00e5c3dea5eb6ac157b7c463220f95c21f /sbin/dhclient
parent574d003669e9f6a8e4d129189d1446d6fdd9faa5 (diff)
Remove confusing extra address abstraction 'struct iaddr'. Just use
'in_addr'. Remove many double conversions and other perversions. piaddr() replaced with inet_ntoa(). dhclient is extremely unlikely to support anything but ipv4/dhcp without a complete rewrite. Joint work with chris@. Positive feedback from deraadt@ zinke@ phessler@.
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/Makefile4
-rw-r--r--sbin/dhclient/clparse.c19
-rw-r--r--sbin/dhclient/dhclient.c105
-rw-r--r--sbin/dhclient/dhcpd.h53
-rw-r--r--sbin/dhclient/dispatch.c34
-rw-r--r--sbin/dhclient/kroute.c57
-rw-r--r--sbin/dhclient/options.c16
-rw-r--r--sbin/dhclient/parse.c8
-rw-r--r--sbin/dhclient/privsep.c5
9 files changed, 137 insertions, 164 deletions
diff --git a/sbin/dhclient/Makefile b/sbin/dhclient/Makefile
index a053d3f2c65..5a90bac50fd 100644
--- a/sbin/dhclient/Makefile
+++ b/sbin/dhclient/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.13 2012/10/30 18:39:44 krw Exp $
+# $OpenBSD: Makefile,v 1.14 2012/11/08 21:32:55 krw Exp $
#
# Copyright (c) 1996, 1997 The Internet Software Consortium.
# All rights reserved.
@@ -33,7 +33,7 @@
.include <bsd.own.mk>
SRCS= dhclient.c clparse.c dispatch.c bpf.c options.c \
- conflex.c errwarn.c inet.c packet.c convert.c tables.c \
+ conflex.c errwarn.c packet.c convert.c tables.c \
parse.c privsep.c kroute.c
PROG= dhclient
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index 72a1cd9065c..cf503c45760 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clparse.c,v 1.42 2012/10/30 18:39:44 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.43 2012/11/08 21:32:55 krw Exp $ */
/* Parser for dhclient config and lease files... */
@@ -431,7 +431,7 @@ parse_client_lease_statement(FILE *cfile, int is_static)
*/
pl = NULL;
for (lp = client->leases; lp; lp = lp->next) {
- if (addr_eq(lp->address, lease->address)) {
+ if (lp->address.s_addr == lease->address.s_addr) {
if (pl)
pl->next = lp->next;
else
@@ -469,7 +469,8 @@ parse_client_lease_statement(FILE *cfile, int is_static)
if (client->active) {
if (client->active->expiry < time(NULL))
free_client_lease(client->active);
- else if (addr_eq(client->active->address, lease->address))
+ else if (client->active->address.s_addr ==
+ lease->address.s_addr)
free_client_lease(client->active);
else {
client->active->next = client->leases;
@@ -563,7 +564,7 @@ parse_option_decl(FILE *cfile, struct option_data *options)
u_int8_t hunkbuf[1024];
int hunkix = 0;
char *fmt;
- struct iaddr ip_addr;
+ struct in_addr ip_addr;
u_int8_t *dp;
int len, code;
int nul_term = 0;
@@ -620,8 +621,8 @@ parse_option_decl(FILE *cfile, struct option_data *options)
case 'I': /* IP address. */
if (!parse_ip_addr(cfile, &ip_addr))
return (-1);
- len = ip_addr.len;
- dp = ip_addr.iabuf;
+ len = sizeof(ip_addr);
+ dp = (char *)&ip_addr;
alloc:
if (hunkix + len > sizeof(hunkbuf)) {
parse_warn("option data buffer "
@@ -713,8 +714,8 @@ bad_flag:
void
parse_reject_statement(FILE *cfile)
{
- struct iaddrlist *list;
- struct iaddr addr;
+ struct reject_elem *list;
+ struct in_addr addr;
int token;
do {
@@ -724,7 +725,7 @@ parse_reject_statement(FILE *cfile)
return;
}
- list = malloc(sizeof(struct iaddrlist));
+ list = malloc(sizeof(struct reject_elem));
if (!list)
error("no memory for reject list!");
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index e89901d7424..d97133feecf 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.169 2012/11/07 15:40:13 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.170 2012/11/08 21:32:55 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -76,9 +76,8 @@ int no_daemon;
int unknown_ok = 1;
int routefd = -1;
-struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } };
-struct iaddr iaddr_deleting;
-struct iaddr iaddr_adding;
+struct in_addr deleting;
+struct in_addr adding;
struct in_addr inaddr_any;
struct sockaddr_in sockaddr_broadcast;
@@ -154,20 +153,19 @@ get_ifa(char *cp, int n)
return (NULL);
}
-struct iaddr defaddr = { 4 };
void
routehandler(void)
{
- int linkstat;
char msg[2048];
+ struct in_addr a;
+ ssize_t n;
+ int linkstat;
struct rt_msghdr *rtm;
struct if_msghdr *ifm;
struct ifa_msghdr *ifam;
struct if_announcemsghdr *ifan;
struct sockaddr *sa;
- struct iaddr a;
- ssize_t n;
char *errmsg;
do {
@@ -195,10 +193,8 @@ routehandler(void)
goto die;
}
- if ((a.len = sizeof(struct in_addr)) > sizeof(a.iabuf))
- error("king bula sez: len mismatch");
- memcpy(a.iabuf, &((struct sockaddr_in *)sa)->sin_addr, a.len);
- if (addr_eq(a, defaddr))
+ memcpy(&a, &((struct sockaddr_in *)sa)->sin_addr, sizeof(a));
+ if (a.s_addr == INADDR_ANY)
break;
/*
@@ -206,14 +202,14 @@ routehandler(void)
* messages generated by that process.
*/
if (rtm->rtm_type == RTM_NEWADDR) {
- if (addr_eq(a, iaddr_adding)) {
- iaddr_adding = defaddr;
+ if (a.s_addr == adding.s_addr) {
+ adding.s_addr = INADDR_ANY;
break;
}
errmsg = "interface address added";
} else {
- if (addr_eq(a, iaddr_deleting)) {
- iaddr_deleting = defaddr;
+ if (a.s_addr == deleting.s_addr) {
+ deleting.s_addr = INADDR_ANY;
break;
}
errmsg = "interface address deleted";
@@ -482,7 +478,7 @@ state_reboot(void)
/* Make a DHCPREQUEST packet, and set appropriate per-interface
flags. */
make_request(client->active);
- client->destination = iaddr_broadcast;
+ client->destination.s_addr = INADDR_BROADCAST;
client->first_sending = time(NULL);
client->interval = 0;
@@ -500,7 +496,7 @@ state_init(void)
flags. */
make_discover(client->active);
client->xid = client->packet.xid;
- client->destination = iaddr_broadcast;
+ client->destination.s_addr = INADDR_BROADCAST;
client->state = S_SELECTING;
client->first_sending = time(NULL);
client->interval = 0;
@@ -568,7 +564,7 @@ state_selecting(void)
}
/* Go to the REQUESTING state. */
- client->destination = iaddr_broadcast;
+ client->destination.s_addr = INADDR_BROADCAST;
client->state = S_REQUESTING;
client->first_sending = cur_time;
client->interval = 0;
@@ -584,7 +580,7 @@ state_selecting(void)
}
void
-dhcpack(struct iaddr client_addr, struct option_data *options)
+dhcpack(struct in_addr client_addr, struct option_data *options)
{
struct client_lease *lease;
time_t cur_time;
@@ -655,10 +651,9 @@ dhcpack(struct iaddr client_addr, struct option_data *options)
void
bind_lease(void)
{
- struct iaddr gateway;
+ struct in_addr gateway, mask;
struct option_data *options;
struct client_lease *lease;
- in_addr_t mask;
char *domainname, *nameservers;
delete_old_addresses(ifi->name, ifi->rdomain);
@@ -667,13 +662,12 @@ bind_lease(void)
lease = apply_defaults(client->new);
options = lease->options;
- memcpy(&mask, options[DHO_SUBNET_MASK].data, sizeof(mask));
+ memcpy(&mask.s_addr, options[DHO_SUBNET_MASK].data, sizeof(in_addr_t));
add_new_address(ifi->name, ifi->rdomain, client->new->address, mask);
if (options[DHO_ROUTERS].len) {
memset(&gateway, 0, sizeof(gateway));
/* XXX Only use FIRST router address for now. */
- gateway.len = sizeof(in_addr_t);
- memcpy(gateway.iabuf, options[DHO_ROUTERS].data,
+ memcpy(&gateway.s_addr, options[DHO_ROUTERS].data,
sizeof(in_addr_t));
add_default_route(ifi->rdomain, client->new->address, gateway);
}
@@ -708,7 +702,7 @@ bind_lease(void)
set_timeout(client->active->renewal, state_bound);
note("bound to %s -- renewal in %lld seconds.",
- piaddr(client->active->address),
+ inet_ntoa(client->active->address),
(long long)(client->active->renewal - time(NULL)));
client->state = S_BOUND;
go_daemon();
@@ -728,12 +722,11 @@ state_bound(void)
client->xid = client->packet.xid;
if (client->active->options[DHO_DHCP_SERVER_IDENTIFIER].len == 4) {
- memcpy(client->destination.iabuf,
+ memcpy(&client->destination.s_addr,
client->active->options[DHO_DHCP_SERVER_IDENTIFIER].data,
- 4);
- client->destination.len = 4;
+ sizeof(in_addr_t));
} else
- client->destination = iaddr_broadcast;
+ client->destination.s_addr = INADDR_BROADCAST;
client->first_sending = time(NULL);
client->interval = 0;
@@ -743,7 +736,7 @@ state_bound(void)
}
void
-dhcpoffer(struct iaddr client_addr, struct option_data *options)
+dhcpoffer(struct in_addr client_addr, struct option_data *options)
{
struct client_lease *lease, *lp;
int i;
@@ -766,9 +759,8 @@ dhcpoffer(struct iaddr client_addr, struct option_data *options)
/* If we've already seen this lease, don't record it again. */
for (lease = client->offered_leases;
lease; lease = lease->next) {
- if (lease->address.len == sizeof(client->packet.yiaddr) &&
- !memcmp(lease->address.iabuf,
- &client->packet.yiaddr, lease->address.len)) {
+ if (!memcmp(&lease->address.s_addr, &client->packet.yiaddr,
+ sizeof(in_addr_t))) {
#ifdef DEBUG
debug("%s already seen.", name);
#endif
@@ -799,7 +791,7 @@ dhcpoffer(struct iaddr client_addr, struct option_data *options)
/* If this is the lease we asked for, put it at the head of the
list, and don't mess with the arp request timeout. */
- if (addr_eq(lease->address, client->requested_address)) {
+ if (lease->address.s_addr == client->requested_address.s_addr) {
lease->next = client->offered_leases;
client->offered_leases = lease;
} else {
@@ -830,7 +822,7 @@ dhcpoffer(struct iaddr client_addr, struct option_data *options)
* parameters in the specified packet.
*/
struct client_lease *
-packet_to_lease(struct iaddr client_addr, struct option_data *options)
+packet_to_lease(struct in_addr client_addr, struct option_data *options)
{
struct client_lease *lease;
int i;
@@ -858,9 +850,8 @@ packet_to_lease(struct iaddr client_addr, struct option_data *options)
}
}
- lease->address.len = sizeof(client->packet.yiaddr);
- memcpy(lease->address.iabuf, &client->packet.yiaddr,
- lease->address.len);
+ memcpy(&lease->address.s_addr, &client->packet.yiaddr,
+ sizeof(in_addr_t));
/* If the server name was filled out, copy it. */
if ((!lease->options[DHO_DHCP_OPTION_OVERLOAD].len ||
@@ -900,7 +891,7 @@ packet_to_lease(struct iaddr client_addr, struct option_data *options)
}
void
-dhcpnak(struct iaddr client_addr, struct option_data *options)
+dhcpnak(struct in_addr client_addr, struct option_data *options)
{
if (client->state != S_REBOOTING &&
client->state != S_REQUESTING &&
@@ -1014,7 +1005,7 @@ state_panic(void)
while (client->active) {
if (client->active->expiry > cur_time) {
note("Trying recorded lease %s",
- piaddr(client->active->address));
+ inet_ntoa(client->active->address));
/*
* If the old lease is still good and doesn't
@@ -1144,14 +1135,13 @@ send_request(void)
cur_time > client->active->rebind)
destination.sin_addr.s_addr = INADDR_BROADCAST;
else
- memcpy(&destination.sin_addr.s_addr, client->destination.iabuf,
- sizeof(destination.sin_addr.s_addr));
+ destination.sin_addr.s_addr = client->destination.s_addr;
destination.sin_port = htons(REMOTE_PORT);
destination.sin_family = AF_INET;
destination.sin_len = sizeof(destination);
if (client->state != S_REQUESTING)
- memcpy(&from, client->active->address.iabuf, sizeof(from));
+ from.s_addr = client->active->address.s_addr;
else
from.s_addr = INADDR_ANY;
@@ -1207,10 +1197,10 @@ make_discover(struct client_lease *lease)
if (lease) {
client->requested_address = lease->address;
i = DHO_DHCP_REQUESTED_ADDRESS;
- options[i].data = lease->address.iabuf;
- options[i].len = lease->address.len;
+ options[i].data = (char *)&lease->address;
+ options[i].len = sizeof(lease->address);
} else
- client->requested_address.len = 0;
+ client->requested_address.s_addr = INADDR_ANY;
/* Send any options requested in the config file. */
for (i = 0; i < 256; i++)
@@ -1276,10 +1266,9 @@ make_request(struct client_lease * lease)
client->state == S_REBOOTING) {
client->requested_address = lease->address;
i = DHO_DHCP_REQUESTED_ADDRESS;
- options[i].data = lease->address.iabuf;
- options[i].len = lease->address.len;
- } else
- client->requested_address.len = 0;
+ options[i].data = (char *)&lease->address.s_addr;
+ options[i].len = sizeof(in_addr_t);
+ }
/* Send any options requested in the config file. */
for (i = 0; i < 256; i++)
@@ -1309,8 +1298,8 @@ make_request(struct client_lease * lease)
if (client->state == S_BOUND ||
client->state == S_RENEWING ||
client->state == S_REBINDING) {
- memcpy(&client->packet.ciaddr,
- lease->address.iabuf, lease->address.len);
+ memcpy(&client->packet.ciaddr, &lease->address.s_addr,
+ sizeof(in_addr_t));
} else {
memset(&client->packet.ciaddr, 0,
sizeof(client->packet.ciaddr));
@@ -1345,8 +1334,8 @@ make_decline(struct client_lease *lease)
/* Send back the address we're declining. */
i = DHO_DHCP_REQUESTED_ADDRESS;
- options[i].data = lease->address.iabuf;
- options[i].len = lease->address.len;
+ options[i].data = (char *)&lease->address.s_addr;
+ options[i].len = sizeof(in_addr_t);
/* Send the uid if the user supplied one. */
i = DHO_DHCP_CLIENT_IDENTIFIER;
@@ -1408,8 +1397,8 @@ rewrite_client_leases(void)
rewind(leaseFile);
for (lp = client->leases; lp; lp = lp->next) {
- if (client->active && addr_eq(lp->address,
- client->active->address))
+ if (client->active && lp->address.s_addr ==
+ client->active->address.s_addr)
continue;
write_client_lease(lp);
}
@@ -1440,7 +1429,7 @@ write_client_lease(struct client_lease *lease)
if (lease->is_bootp)
fprintf(leaseFile, " bootp;\n");
fprintf(leaseFile, " interface \"%s\";\n", ifi->name);
- fprintf(leaseFile, " fixed-address %s;\n", piaddr(lease->address));
+ fprintf(leaseFile, " fixed-address %s;\n", inet_ntoa(lease->address));
if (lease->filename)
fprintf(leaseFile, " filename \"%s\";\n", lease->filename);
if (lease->server_name)
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 4dcd7afad19..1af1429e245 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.90 2012/11/07 17:42:52 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.91 2012/11/08 21:32:55 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -83,14 +83,9 @@ struct option_data {
u_int8_t *data;
};
-struct iaddr {
- int len;
- unsigned char iabuf[16];
-};
-
-struct iaddrlist {
- struct iaddrlist *next;
- struct iaddr addr;
+struct reject_elem {
+ struct reject_elem *next;
+ struct in_addr addr;
};
struct hardware {
@@ -102,7 +97,7 @@ struct hardware {
struct client_lease {
struct client_lease *next;
time_t expiry, renewal, rebind;
- struct iaddr address;
+ struct in_addr address;
char *server_name;
char *filename;
unsigned int is_static : 1;
@@ -144,7 +139,7 @@ struct client_config {
time_t backoff_cutoff;
enum { IGNORE, ACCEPT, PREFER }
bootp_policy;
- struct iaddrlist *reject_list;
+ struct reject_elem *reject_list;
};
struct client_state {
@@ -153,14 +148,14 @@ struct client_state {
struct client_lease *offered_leases;
struct client_lease *leases;
enum dhcp_state state;
- struct iaddr destination;
+ struct in_addr destination;
u_int32_t xid;
u_int16_t secs;
time_t first_sending;
time_t interval;
struct dhcp_packet packet;
int packet_length;
- struct iaddr requested_address;
+ struct in_addr requested_address;
};
struct interface_info {
@@ -197,13 +192,13 @@ extern struct interface_info *ifi;
extern struct client_state *client;
extern struct client_config *config;
extern int privfd;
-extern struct iaddr iaddr_deleting;
-extern struct iaddr iaddr_adding;
+extern struct in_addr deleting;
+extern struct in_addr adding;
/* options.c */
int cons_options(struct option_data *);
char *pretty_print_option(unsigned int, struct option_data *, int);
-void do_packet(int, unsigned int, struct iaddr, struct hardware *);
+void do_packet(int, unsigned int, struct in_addr, struct hardware *);
/* errwarn.c */
extern int warnings_occurred;
@@ -226,7 +221,7 @@ int peek_token(char **, FILE *);
void skip_to_semi(FILE *);
int parse_semi(FILE *);
char *parse_string(FILE *);
-int parse_ip_addr(FILE *, struct iaddr *);
+int parse_ip_addr(FILE *, struct in_addr *);
void parse_hardware_param(FILE *, struct hardware *);
void parse_lease_time(FILE *, time_t *);
int parse_numeric_aggregate(FILE *, unsigned char *, int, int, int);
@@ -265,19 +260,15 @@ void putLong(unsigned char *, int32_t);
void putUShort(unsigned char *, unsigned int);
void putShort(unsigned char *, int);
-/* inet.c */
-int addr_eq(struct iaddr, struct iaddr);
-char *piaddr(struct iaddr);
-
/* dhclient.c */
extern char *path_dhclient_conf;
extern char *path_dhclient_db;
extern int log_perror;
extern int routefd;
-void dhcpoffer(struct iaddr, struct option_data *);
-void dhcpack(struct iaddr, struct option_data *);
-void dhcpnak(struct iaddr, struct option_data *);
+void dhcpoffer(struct in_addr, struct option_data *);
+void dhcpack(struct in_addr, struct option_data *);
+void dhcpnak(struct in_addr, struct option_data *);
void send_discover(void);
void send_request(void);
@@ -299,7 +290,7 @@ void free_client_lease(struct client_lease *);
void rewrite_client_leases(void);
void write_client_lease(struct client_lease *);
-struct client_lease *packet_to_lease(struct iaddr, struct option_data *);
+struct client_lease *packet_to_lease(struct in_addr, struct option_data *);
void go_daemon(void);
void routehandler(void);
@@ -328,14 +319,14 @@ void parse_reject_statement(FILE *);
/* kroute.c */
void delete_old_addresses(char *, int);
-void delete_old_address(char *, int, struct iaddr);
-void priv_delete_old_address(char *, int, struct iaddr);
+void delete_old_address(char *, int, struct in_addr);
+void priv_delete_old_address(char *, int, struct in_addr);
-void add_new_address(char *, int, struct iaddr, in_addr_t);
-void priv_add_new_address(char *, int, struct iaddr, in_addr_t);
+void add_new_address(char *, int, struct in_addr, struct in_addr);
+void priv_add_new_address(char *, int, struct in_addr, struct in_addr);
void flush_routes_and_arp_cache(int);
void priv_flush_routes_and_arp_cache(int);
-void add_default_route(int, struct iaddr, struct iaddr);
-void priv_add_default_route(int, struct iaddr, struct iaddr);
+void add_default_route(int, struct in_addr, struct in_addr);
+void priv_add_default_route(int, struct in_addr, struct in_addr);
diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c
index c3d49ea5637..3b0d17128f9 100644
--- a/sbin/dhclient/dispatch.c
+++ b/sbin/dhclient/dispatch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dispatch.c,v 1.64 2012/11/07 15:20:28 krw Exp $ */
+/* $OpenBSD: dispatch.c,v 1.65 2012/11/08 21:32:55 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -187,7 +187,7 @@ got_one(void)
{
struct sockaddr_in from;
struct hardware hfrom;
- struct iaddr ifrom;
+ struct in_addr ifrom;
ssize_t result;
if ((result = receive_packet(&from, &hfrom)) == -1) {
@@ -205,8 +205,7 @@ got_one(void)
if (result == 0)
return;
- ifrom.len = 4;
- memcpy(ifrom.iabuf, &from.sin_addr, ifrom.len);
+ memcpy(&ifrom, &from.sin_addr, sizeof(ifrom));
do_packet(result, from.sin_port, ifrom, &hfrom);
}
@@ -348,12 +347,13 @@ int
subnet_exists(struct client_lease *l)
{
struct ifaddrs *ifap, *ifa;
- in_addr_t mymask, myaddr, mynet, hismask, hisaddr, hisnet;
+ struct in_addr mymask, myaddr, mynet, hismask, hisaddr, hisnet;
int myrdomain, hisrdomain;
- memcpy(&mymask, l->options[DHO_SUBNET_MASK].data, 4);
- memcpy(&myaddr, l->address.iabuf, 4);
- mynet = mymask & myaddr;
+ memcpy(&mymask.s_addr, l->options[DHO_SUBNET_MASK].data,
+ sizeof(in_addr_t));
+ myaddr.s_addr = l->address.s_addr;
+ mynet.s_addr = mymask.s_addr & myaddr.s_addr;
myrdomain = get_rdomain(ifi->name);
@@ -371,24 +371,26 @@ subnet_exists(struct client_lease *l)
if (hisrdomain != myrdomain)
continue;
- hismask = ((struct sockaddr_in *)ifa->ifa_netmask)->
- sin_addr.s_addr;
- hisaddr = ((struct sockaddr_in *)ifa->ifa_addr)->
- sin_addr.s_addr;
- hisnet = hisaddr & hismask;
+ memcpy(&hismask,
+ &((struct sockaddr_in *)ifa->ifa_netmask)->sin_addr,
+ sizeof(hismask));
+ memcpy(&hisaddr,
+ &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr,
+ sizeof(hisaddr));
+ hisnet.s_addr = hisaddr.s_addr & hismask.s_addr;
- if (hisnet == 0)
+ if (hisnet.s_addr == INADDR_ANY)
continue;
/* Would his packets go out *my* interface? */
- if (mynet == (hisaddr & mymask)) {
+ if (mynet.s_addr == (hisaddr.s_addr & mymask.s_addr)) {
note("interface %s already has the offered subnet!",
ifa->ifa_name);
return (1);
}
/* Would my packets go out *his* interface? */
- if (hisnet == (myaddr & hismask)) {
+ if (hisnet.s_addr == (myaddr.s_addr & hismask.s_addr)) {
note("interface %s already has the offered subnet!",
ifa->ifa_name);
return (1);
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index ff0b8f98996..0fb9ab4da75 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.13 2012/11/08 16:40:21 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.14 2012/11/08 21:32:55 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -189,8 +189,8 @@ priv_flush_routes_and_arp_cache(int rdomain)
* depending on the contents of the gateway parameter.
*/
void
-add_default_route(int rdomain, struct iaddr addr,
- struct iaddr gateway)
+add_default_route(int rdomain, struct in_addr addr,
+ struct in_addr gateway)
{
size_t len;
struct imsg_hdr hdr;
@@ -221,8 +221,8 @@ add_default_route(int rdomain, struct iaddr addr,
}
void
-priv_add_default_route(int rdomain, struct iaddr addr,
- struct iaddr router)
+priv_add_default_route(int rdomain, struct in_addr addr,
+ struct in_addr router)
{
struct rt_msghdr rtm;
struct sockaddr_in dest, gateway, mask;
@@ -272,7 +272,7 @@ priv_add_default_route(int rdomain, struct iaddr addr,
if (bcmp(&router, &addr, sizeof(addr)) != 0) {
gateway.sin_len = sizeof(gateway);
gateway.sin_family = AF_INET;
- gateway.sin_addr.s_addr = inet_addr(piaddr(router));
+ gateway.sin_addr.s_addr = router.s_addr;
rtm.rtm_flags |= RTF_GATEWAY | RTF_STATIC;
rtm.rtm_addrs |= RTA_GATEWAY;
@@ -330,15 +330,12 @@ priv_add_default_route(int rdomain, struct iaddr addr,
void
delete_old_addresses(char *ifname, int rdomain)
{
- struct iaddr addr;
+ struct in_addr addr;
struct ifaddrs *ifap, *ifa;
if (getifaddrs(&ifap) != 0)
error("delete_old_addresses getifaddrs: %m");
- if (sizeof(struct in_addr) > sizeof(addr.iabuf))
- error("king bula sez: len mismatch in delete_old_addresses");
-
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if ((ifa->ifa_flags & IFF_LOOPBACK) ||
(ifa->ifa_flags & IFF_POINTOPOINT) ||
@@ -348,9 +345,9 @@ delete_old_addresses(char *ifname, int rdomain)
continue;
memset(&addr, 0, sizeof(addr));
- addr.len = sizeof(struct in_addr);
- memcpy(addr.iabuf,
- &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr, addr.len);
+ memcpy(&addr,
+ &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr,
+ sizeof(in_addr_t));
delete_old_address(ifi->name, ifi->rdomain, addr);
}
@@ -365,14 +362,14 @@ delete_old_addresses(char *ifname, int rdomain)
* route -q <rdomain> delete <addr> 127.0.0.1
*/
void
-delete_old_address(char *ifname, int rdomain, struct iaddr addr)
+delete_old_address(char *ifname, int rdomain, struct in_addr addr)
{
size_t len;
struct imsg_hdr hdr;
struct buf *buf;
- /* Note the address we are deleting for RTM_DELADDR filtering! */
- iaddr_deleting = addr;
+ /* Note the address we are deeleting for RTM_DELADDR filtering! */
+ deleting.s_addr = addr.s_addr;
hdr.code = IMSG_DELETE_ADDRESS;
hdr.len = sizeof(hdr) +
@@ -399,13 +396,12 @@ delete_old_address(char *ifname, int rdomain, struct iaddr addr)
}
void
-priv_delete_old_address(char *ifname, int rdomain, struct iaddr addr)
+priv_delete_old_address(char *ifname, int rdomain, struct in_addr addr)
{
struct ifaliasreq ifaliasreq;
struct rt_msghdr rtm;
struct sockaddr_in dest, gateway;
struct iovec iov[3];
- in_addr_t bozo;
struct sockaddr_in *in;
int s, iovcnt = 0;
@@ -422,13 +418,11 @@ priv_delete_old_address(char *ifname, int rdomain, struct iaddr addr)
in = (struct sockaddr_in *)&ifaliasreq.ifra_addr;
in->sin_family = AF_INET;
in->sin_len = sizeof(ifaliasreq.ifra_addr);
-
- bozo = inet_addr(piaddr(addr));
- memcpy(&in->sin_addr.s_addr, &bozo, sizeof(bozo));
+ in->sin_addr.s_addr = addr.s_addr;
/* SIOCDIFADDR will result in a RTM_DELADDR message we must catch! */
if (ioctl(s, SIOCDIFADDR, &ifaliasreq) == -1) {
- warning("SIOCDIFADDR failed (%s): %m", piaddr(addr));
+ warning("SIOCDIFADDR failed (%s): %m", inet_ntoa(addr));
close(s);
return;
}
@@ -461,7 +455,7 @@ priv_delete_old_address(char *ifname, int rdomain, struct iaddr addr)
dest.sin_len = sizeof(dest);
dest.sin_family = AF_INET;
- dest.sin_addr.s_addr = inet_addr(piaddr(addr));
+ dest.sin_addr.s_addr = addr.s_addr;
rtm.rtm_addrs |= RTA_DST;
rtm.rtm_msglen += sizeof(dest);
@@ -498,13 +492,14 @@ priv_delete_old_address(char *ifname, int rdomain, struct iaddr addr)
* route -q <rdomain> add <addr> 127.0.0.1
*/
void
-add_new_address(char *ifname, int rdomain, struct iaddr addr, in_addr_t mask)
+add_new_address(char *ifname, int rdomain, struct in_addr addr,
+ struct in_addr mask)
{
struct buf *buf;
size_t len;
struct imsg_hdr hdr;
- iaddr_adding = addr;
+ adding = addr;
hdr.code = IMSG_ADD_ADDRESS;
hdr.len = sizeof(hdr) +
@@ -536,8 +531,8 @@ add_new_address(char *ifname, int rdomain, struct iaddr addr, in_addr_t mask)
}
void
-priv_add_new_address(char *ifname, int rdomain, struct iaddr addr,
- in_addr_t mask)
+priv_add_new_address(char *ifname, int rdomain, struct in_addr addr,
+ struct in_addr mask)
{
struct ifaliasreq ifaliasreq;
struct rt_msghdr rtm;
@@ -545,7 +540,6 @@ priv_add_new_address(char *ifname, int rdomain, struct iaddr addr,
struct sockaddr_rtlabel label;
struct iovec iov[4];
struct sockaddr_in *in;
- in_addr_t bozo;
int s, len, i, iovcnt = 0;
/*
@@ -562,8 +556,7 @@ priv_add_new_address(char *ifname, int rdomain, struct iaddr addr,
in = (struct sockaddr_in *)&ifaliasreq.ifra_addr;
in->sin_family = AF_INET;
in->sin_len = sizeof(ifaliasreq.ifra_addr);
- bozo = inet_addr(piaddr(addr));
- memcpy(&in->sin_addr.s_addr, &bozo, sizeof(bozo));
+ in->sin_addr.s_addr = addr.s_addr;
/* And the netmask in ifra_mask. */
in = (struct sockaddr_in *)&ifaliasreq.ifra_mask;
@@ -574,7 +567,7 @@ priv_add_new_address(char *ifname, int rdomain, struct iaddr addr,
/* No need to set broadcast address. Kernel can figure it out. */
if (ioctl(s, SIOCAIFADDR, &ifaliasreq) == -1)
- warning("SIOCAIFADDR failed (%s): %m", piaddr(addr));
+ warning("SIOCAIFADDR failed (%s): %m", inet_ntoa(addr));
close(s);
@@ -604,7 +597,7 @@ priv_add_new_address(char *ifname, int rdomain, struct iaddr addr,
dest.sin_len = sizeof(dest);
dest.sin_family = AF_INET;
- dest.sin_addr.s_addr = inet_addr(piaddr(addr));
+ dest.sin_addr.s_addr = addr.s_addr;
rtm.rtm_addrs |= RTA_DST;
rtm.rtm_msglen += sizeof(dest);
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c
index caf51105d29..f7959c6dd68 100644
--- a/sbin/dhclient/options.c
+++ b/sbin/dhclient/options.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: options.c,v 1.43 2012/11/07 15:20:28 krw Exp $ */
+/* $OpenBSD: options.c,v 1.44 2012/11/08 21:32:55 krw Exp $ */
/* DHCP options parsing and reassembly. */
@@ -448,13 +448,13 @@ pretty_print_option(unsigned int code, struct option_data *option,
}
void
-do_packet(int len, unsigned int from_port, struct iaddr from,
+do_packet(int len, unsigned int from_port, struct in_addr from,
struct hardware *hfrom)
{
struct dhcp_packet *packet = &client->packet;
struct option_data options[256];
- struct iaddrlist *ap;
- void (*handler)(struct iaddr, struct option_data *);
+ struct reject_elem *ap;
+ void (*handler)(struct in_addr, struct option_data *);
char *type;
int i, options_valid = 1;
@@ -522,16 +522,16 @@ do_packet(int len, unsigned int from_port, struct iaddr from,
if (handler && client->xid == client->packet.xid) {
if (hfrom->hlen == 6)
- note("%s from %s (%s)", type, piaddr(from),
+ note("%s from %s (%s)", type, inet_ntoa(from),
ether_ntoa((struct ether_addr *)hfrom->haddr));
else
- note("%s from %s", type, piaddr(from));
+ note("%s from %s", type, inet_ntoa(from));
} else
handler = NULL;
for (ap = config->reject_list; ap && handler; ap = ap->next)
- if (addr_eq(from, ap->addr)) {
- note("%s from %s rejected.", type, piaddr(from));
+ if (from.s_addr == ap->addr.s_addr) {
+ note("%s from %s rejected.", type, inet_ntoa(from));
handler = NULL;
}
diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c
index 92c33594463..6a1dc4a62b3 100644
--- a/sbin/dhclient/parse.c
+++ b/sbin/dhclient/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.20 2011/12/10 17:15:27 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.21 2012/11/08 21:32:55 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -133,11 +133,9 @@ parse_string(FILE *cfile)
}
int
-parse_ip_addr(FILE *cfile, struct iaddr *addr)
+parse_ip_addr(FILE *cfile, struct in_addr *addr)
{
- addr->len = 4;
- return (parse_numeric_aggregate(cfile, addr->iabuf, addr->len, '.',
- 10));
+ return (parse_numeric_aggregate(cfile, (char *)addr, 4, '.', 10));
}
/*
diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c
index ae0eb13ee53..f3817b22d36 100644
--- a/sbin/dhclient/privsep.c
+++ b/sbin/dhclient/privsep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.c,v 1.21 2012/11/04 03:44:48 krw Exp $ */
+/* $OpenBSD: privsep.c,v 1.22 2012/11/08 21:32:55 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -94,10 +94,9 @@ void
dispatch_imsg(int fd)
{
struct imsg_hdr hdr;
- in_addr_t *mask;
+ struct in_addr *addr, *mask, *gateway;
char *ifname, *contents;
size_t totlen, len;
- struct iaddr *addr, *gateway;
int rdomain;
buf_read(fd, &hdr, sizeof(hdr));