summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2014-04-17 09:59:31 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2014-04-17 09:59:31 +0000
commit915e3333ad8d3d780820552a29195cfbb3d33c30 (patch)
tree95fbfcc58b0de93ed125fb1158d3c105be12ac9e
parent6f2960419f0a001d10f38049497d919d4c48c300 (diff)
Eliminate a couple of always-NULL parameters. Eliminate some
pointless repetition of well-known info in log messages. Pass around smaller bits of info. Make 'inaddr_any' a const struct initialized with { INADDR_ANY }. Tweaks and ok guenther@
-rw-r--r--sbin/dhclient/bpf.c25
-rw-r--r--sbin/dhclient/dhclient.c29
-rw-r--r--sbin/dhclient/dhcpd.h6
-rw-r--r--sbin/dhclient/packet.c10
4 files changed, 28 insertions, 42 deletions
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c
index d0eaa8f745e..19c1046f515 100644
--- a/sbin/dhclient/bpf.c
+++ b/sbin/dhclient/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.31 2013/12/12 00:22:06 krw Exp $ */
+/* $OpenBSD: bpf.c,v 1.32 2014/04/17 09:59:30 krw Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -261,9 +261,9 @@ if_register_receive(void)
}
ssize_t
-send_packet(struct in_addr from, struct sockaddr_in *to,
- struct ether_addr *hto)
+send_packet(struct in_addr from, struct in_addr to)
{
+ struct sockaddr_in dest;
struct ether_header eh;
struct ip ip;
struct udphdr udp;
@@ -273,8 +273,13 @@ send_packet(struct in_addr from, struct sockaddr_in *to,
ssize_t result;
int iovcnt = 0, len;
- if (to->sin_addr.s_addr == INADDR_BROADCAST) {
- assemble_eh_header(&eh, hto);
+ memset(&dest, 0, sizeof(dest));
+ dest.sin_family = AF_INET;
+ dest.sin_port = htons(REMOTE_PORT);
+ dest.sin_addr.s_addr = to.s_addr;
+
+ if (to.s_addr == INADDR_BROADCAST) {
+ assemble_eh_header(&eh);
iov[0].iov_base = &eh;
iov[0].iov_len = sizeof(eh);
iovcnt++;
@@ -293,14 +298,14 @@ send_packet(struct in_addr from, struct sockaddr_in *to,
ip.ip_p = IPPROTO_UDP;
ip.ip_sum = 0;
ip.ip_src.s_addr = from.s_addr;
- ip.ip_dst.s_addr = to->sin_addr.s_addr;
+ ip.ip_dst.s_addr = to.s_addr;
ip.ip_sum = wrapsum(checksum((unsigned char *)&ip, sizeof(ip), 0));
iov[iovcnt].iov_base = &ip;
iov[iovcnt].iov_len = sizeof(ip);
iovcnt++;
udp.uh_sport = htons(LOCAL_PORT);
- udp.uh_dport = to->sin_port;
+ udp.uh_dport = htons(REMOTE_PORT);
udp.uh_ulen = htons(sizeof(udp) + len);
udp.uh_sum = 0;
udp.uh_sum = wrapsum(checksum((unsigned char *)&udp, sizeof(udp),
@@ -315,12 +320,12 @@ send_packet(struct in_addr from, struct sockaddr_in *to,
iov[iovcnt].iov_len = len;
iovcnt++;
- if (to->sin_addr.s_addr == INADDR_BROADCAST) {
+ if (to.s_addr == INADDR_BROADCAST) {
result = writev(ifi->wfdesc, iov, iovcnt);
} else {
memset(&msg, 0, sizeof(msg));
- msg.msg_name = (struct sockaddr *)to;
- msg.msg_namelen = sizeof(*to);
+ msg.msg_name = (struct sockaddr *)&dest;
+ msg.msg_namelen = sizeof(to);
msg.msg_iov = iov;
msg.msg_iovlen = iovcnt;
result = sendmsg(ifi->ufdesc, &msg, 0);
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 7698bf6dc67..d8518f2502c 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.295 2014/04/16 18:46:41 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.296 2014/04/17 09:59:30 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -83,8 +83,7 @@ volatile sig_atomic_t quit;
struct in_addr deleting;
struct in_addr adding;
-struct in_addr inaddr_any;
-struct sockaddr_in sockaddr_broadcast;
+const struct in_addr inaddr_any = { INADDR_ANY };
struct interface_info *ifi;
struct client_state *client;
@@ -465,13 +464,6 @@ main(int argc, char *argv[])
tzset();
- memset(&sockaddr_broadcast, 0, sizeof(sockaddr_broadcast));
- sockaddr_broadcast.sin_family = AF_INET;
- sockaddr_broadcast.sin_port = htons(REMOTE_PORT);
- sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST;
- sockaddr_broadcast.sin_len = sizeof(sockaddr_broadcast);
- inaddr_any.s_addr = INADDR_ANY;
-
/* Put us into the correct rdomain */
ifi->rdomain = get_rdomain(ifi->name);
if (setrtable(ifi->rdomain) == -1)
@@ -1224,12 +1216,10 @@ send_discover(void)
client->bootrequest_packet.secs = htons(65535);
client->secs = client->bootrequest_packet.secs;
- note("DHCPDISCOVER on %s to %s port %hu interval %lld",
- ifi->name, inet_ntoa(sockaddr_broadcast.sin_addr),
- ntohs(sockaddr_broadcast.sin_port),
+ note("DHCPDISCOVER on %s - interval %lld", ifi->name,
(long long)client->interval);
- send_packet(inaddr_any, &sockaddr_broadcast, NULL);
+ send_packet(inaddr_any, inaddr_any);
set_timeout_interval(client->interval, send_discover);
}
@@ -1402,9 +1392,6 @@ send_request(void)
destination.sin_addr.s_addr = INADDR_BROADCAST;
else
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)
from.s_addr = client->active->address.s_addr;
@@ -1424,7 +1411,7 @@ send_request(void)
note("DHCPREQUEST on %s to %s port %hu", ifi->name,
inet_ntoa(destination.sin_addr), ntohs(destination.sin_port));
- send_packet(from, &destination, NULL);
+ send_packet(from, destination.sin_addr);
set_timeout_interval(client->interval, send_request);
}
@@ -1432,11 +1419,9 @@ send_request(void)
void
send_decline(void)
{
- note("DHCPDECLINE on %s to %s port %hu", ifi->name,
- inet_ntoa(sockaddr_broadcast.sin_addr),
- ntohs(sockaddr_broadcast.sin_port));
+ note("DHCPDECLINE on %s", ifi->name);
- send_packet(inaddr_any, &sockaddr_broadcast, NULL);
+ send_packet(inaddr_any, inaddr_any);
}
void
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 10efd27559d..74ea51314e8 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.136 2014/02/09 20:45:56 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.137 2014/04/17 09:59:30 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -249,7 +249,7 @@ time_t parse_date(FILE *);
/* bpf.c */
void if_register_send(void);
void if_register_receive(void);
-ssize_t send_packet(struct in_addr, struct sockaddr_in *, struct ether_addr *);
+ssize_t send_packet(struct in_addr, struct in_addr);
ssize_t receive_packet(struct sockaddr_in *, struct ether_addr *);
/* dispatch.c */
@@ -288,7 +288,7 @@ void free_client_lease(struct client_lease *);
void routehandler(void);
/* packet.c */
-void assemble_eh_header(struct ether_header *, struct ether_addr *);
+void assemble_eh_header(struct ether_header *);
ssize_t decode_hw_header(unsigned char *, int, struct ether_addr *);
ssize_t decode_udp_ip_header(unsigned char *, int, struct sockaddr_in *,
int);
diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c
index 965414ed537..415c767f4c9 100644
--- a/sbin/dhclient/packet.c
+++ b/sbin/dhclient/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.25 2014/01/20 09:16:36 deraadt Exp $ */
+/* $OpenBSD: packet.c,v 1.26 2014/04/17 09:59:30 krw Exp $ */
/* Packet assembly code, originally contributed by Archie Cobbs. */
@@ -80,13 +80,9 @@ wrapsum(u_int32_t sum)
}
void
-assemble_eh_header(struct ether_header *eh, struct ether_addr *to)
+assemble_eh_header(struct ether_header *eh)
{
- if (to != NULL)
- memcpy(eh->ether_dhost, to->ether_addr_octet,
- sizeof(eh->ether_dhost));
- else
- memset(eh->ether_dhost, 0xff, sizeof(eh->ether_dhost));
+ memset(eh->ether_dhost, 0xff, sizeof(eh->ether_dhost));
memcpy(eh->ether_shost, ifi->hw_address.ether_addr_octet,
sizeof(eh->ether_shost));