diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-04-20 04:19:01 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2004-04-20 04:19:01 +0000 |
commit | 21b3fb8fe8f9ba7c7937a19d5fc0e078633cb938 (patch) | |
tree | c25c114f37f44620840e4d161b0d035adfea8dde /usr.sbin/dhcrelay | |
parent | 8d9b4ffaf487f3986da30ec42946a7f8f57a79f2 (diff) |
more shrinking; ok henning
Diffstat (limited to 'usr.sbin/dhcrelay')
-rw-r--r-- | usr.sbin/dhcrelay/bpf.c | 4 | ||||
-rw-r--r-- | usr.sbin/dhcrelay/dhcpd.h | 109 | ||||
-rw-r--r-- | usr.sbin/dhcrelay/dhcrelay.c | 6 | ||||
-rw-r--r-- | usr.sbin/dhcrelay/dispatch.c | 21 |
4 files changed, 16 insertions, 124 deletions
diff --git a/usr.sbin/dhcrelay/bpf.c b/usr.sbin/dhcrelay/bpf.c index 657aad79af7..7359d94119c 100644 --- a/usr.sbin/dhcrelay/bpf.c +++ b/usr.sbin/dhcrelay/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.1 2004/04/12 21:10:28 henning Exp $ */ +/* $OpenBSD: bpf.c,v 1.2 2004/04/20 04:19:00 deraadt Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -182,7 +182,7 @@ if_register_receive(struct interface_info *info) } ssize_t -send_packet(struct interface_info *interface, struct packet *packet, +send_packet(struct interface_info *interface, struct dhcp_packet *raw, size_t len, struct in_addr from, struct sockaddr_in *to, struct hardware *hto) { diff --git a/usr.sbin/dhcrelay/dhcpd.h b/usr.sbin/dhcrelay/dhcpd.h index b75c6f7c380..914c902fd75 100644 --- a/usr.sbin/dhcrelay/dhcpd.h +++ b/usr.sbin/dhcrelay/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.3 2004/04/20 03:52:36 deraadt Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.4 2004/04/20 04:19:00 deraadt Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -76,57 +76,17 @@ #define LOCAL_PORT 68 #define REMOTE_PORT 67 -struct option_data { - int len; - u_int8_t *data; -}; - -struct string_list { - struct string_list *next; - char *string; -}; - struct iaddr { int len; unsigned char iabuf[16]; }; -struct iaddrlist { - struct iaddrlist *next; - struct iaddr addr; -}; - -struct packet { - struct dhcp_packet *raw; - int packet_length; - int packet_type; - int options_valid; - int client_port; - struct iaddr client_addr; - struct interface_info *interface; - struct hardware *haddr; - struct option_data options[256]; - int got_requested_address; -}; - struct hardware { u_int8_t htype; u_int8_t hlen; u_int8_t haddr[16]; }; -struct client_lease { - struct client_lease *next; - time_t expiry, renewal, rebind; - struct iaddr address; - char *server_name; - char *filename; - struct string_list *medium; - unsigned int is_static : 1; - unsigned int is_bootp : 1; - struct option_data options[256]; -}; - /* Possible states in which the client can be. */ enum dhcp_state { S_REBOOTING, @@ -138,55 +98,6 @@ enum dhcp_state { S_REBINDING }; -struct client_config { - struct option_data defaults[256]; - enum { - ACTION_DEFAULT, - ACTION_SUPERSEDE, - ACTION_PREPEND, - ACTION_APPEND - } default_actions[256]; - - struct option_data send_options[256]; - u_int8_t required_options[256]; - u_int8_t requested_options[256]; - int requested_option_count; - time_t timeout; - time_t initial_interval; - time_t retry_interval; - time_t select_interval; - time_t reboot_timeout; - time_t backoff_cutoff; - struct string_list *media; - char *script_name; - enum { IGNORE, ACCEPT, PREFER } - bootp_policy; - struct string_list *medium; - struct iaddrlist *reject_list; -}; - -struct client_state { - struct client_lease *active; - struct client_lease *new; - struct client_lease *offered_leases; - struct client_lease *leases; - struct client_lease *alias; - enum dhcp_state state; - struct iaddr destination; - u_int32_t xid; - u_int16_t secs; - time_t first_sending; - time_t interval; - struct string_list *medium; - struct dhcp_packet packet; - int packet_length; - struct iaddr requested_address; - struct client_config *config; - char **scriptEnv; - int scriptEnvsize; - struct string_list *env; - int envc; -}; struct interface_info { struct interface_info *next; @@ -200,7 +111,6 @@ struct interface_info { size_t rbuf_offset; size_t rbuf_len; struct ifreq *ifp; - struct client_state *client; int noifmedia; int errors; int dead; @@ -221,20 +131,6 @@ struct protocol { void *local; }; -#define DEFAULT_HASH_SIZE 97 - -struct hash_bucket { - struct hash_bucket *next; - unsigned char *name; - int len; - unsigned char *value; -}; - -struct hash_table { - int hash_count; - struct hash_bucket *buckets[DEFAULT_HASH_SIZE]; -}; - /* Default path to dhcpd config file. */ #define DHCPD_LOG_FACILITY LOG_DAEMON @@ -255,7 +151,7 @@ int if_register_bpf(struct interface_info *); void if_register_send(struct interface_info *); void if_register_receive(struct interface_info *); ssize_t send_packet(struct interface_info *, - struct packet *, struct dhcp_packet *, size_t, struct in_addr, + struct dhcp_packet *, size_t, struct in_addr, struct sockaddr_in *, struct hardware *); ssize_t receive_packet(struct interface_info *, unsigned char *, size_t, struct sockaddr_in *, struct hardware *); @@ -264,7 +160,6 @@ ssize_t receive_packet(struct interface_info *, unsigned char *, size_t, extern void (*bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *); void discover_interfaces(struct interface_info *); -void reinitialize_interfaces(void); void dispatch(void); void got_one(struct protocol *); void add_timeout(time_t, void (*)(void *), void *); diff --git a/usr.sbin/dhcrelay/dhcrelay.c b/usr.sbin/dhcrelay/dhcrelay.c index 6e5e7adbd58..30f53dc5ee0 100644 --- a/usr.sbin/dhcrelay/dhcrelay.c +++ b/usr.sbin/dhcrelay/dhcrelay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcrelay.c,v 1.15 2004/04/20 03:52:36 deraadt Exp $ */ +/* $OpenBSD: dhcrelay.c,v 1.16 2004/04/20 04:19:00 deraadt Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@cvs.openbsd.org> @@ -212,7 +212,7 @@ relay(struct interface_info *ip, struct dhcp_packet *packet, int length, memcpy(hto.haddr, packet->chaddr, hto.hlen); hto.htype = packet->htype; - if (send_packet(interfaces, NULL, packet, length, + if (send_packet(interfaces, packet, length, interfaces->primary_address, &to, &hto) != -1) debug("forwarded BOOTREPLY for %s to %s", print_hw_addr(packet->htype, packet->hlen, @@ -236,7 +236,7 @@ relay(struct interface_info *ip, struct dhcp_packet *packet, int length, /* Otherwise, it's a BOOTREQUEST, so forward it to all the servers. */ for (sp = servers; sp; sp = sp->next) { - if (send_packet(interfaces, NULL, packet, length, + if (send_packet(interfaces, packet, length, ip->primary_address, &sp->to, NULL) != -1) { debug("forwarded BOOTREQUEST for %s to %s", print_hw_addr(packet->htype, packet->hlen, diff --git a/usr.sbin/dhcrelay/dispatch.c b/usr.sbin/dhcrelay/dispatch.c index a38850842ad..d6cb9318586 100644 --- a/usr.sbin/dhcrelay/dispatch.c +++ b/usr.sbin/dhcrelay/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.1 2004/04/12 21:10:28 henning Exp $ */ +/* $OpenBSD: dispatch.c,v 1.2 2004/04/20 04:19:00 deraadt Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -51,6 +51,7 @@ struct protocol *protocols; struct timeout *timeouts; static struct timeout *free_timeouts; static int interfaces_invalidated; + void (*bootp_packet_handler)(struct interface_info *, struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *); @@ -89,6 +90,7 @@ discover_interfaces(struct interface_info *iface) if (ifa->ifa_addr->sa_family == AF_LINK) { struct sockaddr_dl *foo = (struct sockaddr_dl *)ifa->ifa_addr; + iface->index = foo->sdl_index; iface->hw_address.hlen = foo->sdl_alen; iface->hw_address.htype = HTYPE_ETHER; /* XXX */ @@ -102,6 +104,7 @@ discover_interfaces(struct interface_info *iface) continue; if (!iface->ifp) { int len = IFNAMSIZ + ifa->ifa_addr->sa_len; + if ((tif = malloc(len)) == NULL) error("no space to remember ifp"); strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ); @@ -122,16 +125,9 @@ discover_interfaces(struct interface_info *iface) if_register_receive(iface); if_register_send(iface); add_protocol(iface->name, iface->rfdesc, got_one, iface); - freeifaddrs(ifap); } -void -reinitialize_interfaces(void) -{ - interfaces_invalidated = 1; -} - /* * Wait for packets to come in using poll(). When a packet comes in, * call receive_packet to receive the packet and possibly strip hardware @@ -161,9 +157,9 @@ dispatch(void) */ another: if (timeouts) { - struct timeout *t; if (timeouts->when <= cur_time) { - t = timeouts; + struct timeout *t = timeouts; + timeouts = timeouts->next; (*(t->func))(t->what); t->next = free_timeouts; @@ -189,6 +185,7 @@ another: for (l = protocols; l; l = l->next) { struct interface_info *ip = l->local; + if (ip && (l->handler != got_one || !ip->dead)) { fds[i].fd = l->fd; fds[i].events = POLLIN; @@ -218,8 +215,8 @@ another: i = 0; for (l = protocols; l; l = l->next) { - struct interface_info *ip; - ip = l->local; + struct interface_info *ip = l->local; + if ((fds[i].revents & POLLIN)) { fds[i].revents = 0; if (ip && (l->handler != got_one || |