34 # define send_packet trace_packet_send
43 struct packet outgoing;
45 struct sockaddr_in to;
55 int peer_has_leases = 0;
64 snprintf (msgbuf,
sizeof msgbuf,
"BOOTREQUEST from %s via %s",
66 packet -> raw -> hlen,
67 packet -> raw -> chaddr),
68 packet -> raw ->
giaddr.s_addr
69 ? inet_ntoa (packet -> raw ->
giaddr)
70 : packet -> interface -> name);
73 log_info (
"%s: network unknown", msgbuf);
78 0, 0, (
struct lease *)0,
MDL);
80 if (lease && lease->
host)
81 host_reference(&hp, lease->
host,
MDL);
94 packet->raw->hlen,
MDL);
98 host_reference(&host, h,
MDL);
104 host_dereference(&hp,
MDL);
107 host_reference(&hp, host,
MDL);
108 host_dereference(&host,
MDL);
118 log_info(
"%s: BOOTP from dynamic client and no "
119 "dynamic leases", msgbuf);
123 #if defined(FAILOVER_PROTOCOL)
124 if ((lease->
pool != NULL) &&
126 dhcp_failover_state_t *peer;
142 log_info(
"%s: load balance to peer %s",
149 ack_lease (packet, lease, 0, 0, msgbuf, 0, hp);
159 packet->options, options,
164 for (i = packet -> class_count; i > 0; i--) {
166 packet->options, options,
168 packet->classes[i - 1]->group,
175 packet->options, options,
184 packet->options, options,
187 log_info (
"%s: bootp disallowed", msgbuf);
195 packet->options, options,
198 log_info (
"%s: booting disallowed", msgbuf);
203 memset (&outgoing, 0,
sizeof outgoing);
204 memset (&raw, 0,
sizeof raw);
210 if (!packet->options_valid &&
212 packet->options, options,
215 options, i),
MDL))) {
217 memcpy(outgoing.
raw->
options, packet->raw->options,
224 : packet->packet_length;
235 lease ->
subnet -> netmask.iabuf,
236 lease ->
subnet -> netmask.len,
238 option_code_hash_lookup(&oc->
option,
260 packet -> options, options,
270 raw.
htype = packet -> raw -> htype;
271 raw.
hlen = packet -> raw -> hlen;
272 memcpy (raw.
chaddr, packet -> raw -> chaddr,
sizeof raw.
chaddr);
273 raw.
hops = packet -> raw -> hops;
274 raw.
xid = packet -> raw -> xid;
275 raw.
secs = packet -> raw -> secs;
277 raw.
ciaddr = packet -> raw -> ciaddr;
288 packet -> options, options,
289 &lease -> scope, oc,
MDL))
293 memset (&d1, 0,
sizeof d1);
298 packet -> options, options,
299 &lease -> scope, oc,
MDL)) {
309 else if (packet->interface->address_count)
310 raw.
siaddr = packet->interface->addresses[0];
320 packet -> options, options,
321 &lease -> scope, oc,
MDL)) {
326 0, (
sizeof raw.
file) - d1.
len);
329 memcpy (raw.
file, packet -> raw ->
file,
sizeof raw.
file);
336 packet -> options, options,
337 &lease -> scope, oc,
MDL)) {
355 hto.
hbuf [0] = packet -> raw -> htype;
356 hto.
hlen = packet -> raw -> hlen + 1;
357 memcpy (&hto.
hbuf [1], packet -> raw -> chaddr, packet -> raw -> hlen);
359 if (packet->interface->address_count) {
360 from = packet->interface->addresses[0];
362 log_error(
"%s: Interface %s appears to have no IPv4 "
363 "addresses, and so dhcpd cannot select a source "
364 "address.", msgbuf, packet->interface->name);
370 log_info(
"BOOTREPLY for %s to %s (%s) via %s",
372 ((hp != NULL) && (hp->
name != NULL)) ? hp -> name :
"unknown",
375 packet->raw->chaddr),
376 packet->raw->giaddr.s_addr
377 ? inet_ntoa (packet->raw->giaddr)
378 : packet->interface->name);
381 to.sin_family = AF_INET;
383 to.sin_len =
sizeof to;
385 memset (to.sin_zero, 0,
sizeof to.sin_zero);
397 log_error (
"%s:%d: Failed to send %d byte long "
398 "packet over %s interface.",
MDL,
405 }
else if (norelay == 2) {
431 result =
send_packet(packet->interface, packet, &raw,
434 log_error (
"%s:%d: Failed to send %d byte long packet over %s"
436 packet->interface->name);
444 lease_dereference (&lease,
MDL);
446 host_dereference (&hp,
MDL);
448 host_dereference (&host,
MDL);
#define DHCP_FIXED_NON_UDP
int find_lease(struct lease **, struct packet *, struct shared_network *, int *, int *, struct lease *, const char *, int)
char sname[DHCP_SNAME_LEN]
void save_option(struct universe *universe, struct option_state *options, struct option_cache *oc)
const char * piaddr(const struct iaddr addr)
int option_cache_dereference(struct option_cache **ptr, const char *file, int line)
struct universe server_universe
int execute_statements(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct executable_statement *statements, struct on_star *on_star)
char * print_hw_addr(int htype, const int hlen, const unsigned char *data) const
struct in_addr * addresses
struct universe dhcp_universe
void data_string_forget(struct data_string *data, const char *file, int line)
struct option_cache * fixed_addr
int log_error(const char *,...) __attribute__((__format__(__printf__
int allocate_lease(struct lease **, struct packet *, struct pool *, int *)
dhcp_failover_state_t * failover_peer
int find_hosts_by_haddr(struct host_decl **, int, const unsigned char *, unsigned, const char *, int)
int locate_network(struct packet *)
int option_cache_allocate(struct option_cache **cptr, const char *file, int line)
void execute_statements_in_scope(struct binding_value **result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *out_options, struct binding_scope **scope, struct group *group, struct group *limiting_group, struct on_star *on_star)
struct interface_info * fallback_interface
int option_state_allocate(struct option_state **ptr, const char *file, int line)
int evaluate_option_cache(struct data_string *result, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
#define SV_ALWAYS_BROADCAST
#define SV_ALWAYS_REPLY_RFC1048
ssize_t send_packet(struct interface_info *, struct packet *, struct dhcp_packet *, size_t, struct in_addr, struct sockaddr_in *, struct hardware *)
int cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, struct lease *lease, struct client_state *client_state, int mms, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, int overload_avail, int terminate, int bootpp, struct data_string *prl, const char *vuname)
struct host_decl * n_ipaddr
int load_balance_mine(struct packet *, dhcp_failover_state_t *)
struct option_cache * lookup_option(struct universe *universe, struct option_state *options, unsigned code)
struct in_addr limited_broadcast
int int log_info(const char *,...) __attribute__((__format__(__printf__
struct shared_network * shared_network
void bootp(struct packet *packet)
void use_host_decl_name(struct packet *, struct lease *, struct option_state *)
Adds hostname option when use-host-decl-names is enabled.
int option_state_dereference(struct option_state **ptr, const char *file, int line)
int evaluate_boolean_option_cache(int *ignorep, struct packet *packet, struct lease *lease, struct client_state *client_state, struct option_state *in_options, struct option_state *cfg_options, struct binding_scope **scope, struct option_cache *oc, const char *file, int line)
int make_const_data(struct expression **expr, const unsigned char *data, unsigned len, int terminated, int allocate, const char *file, int line)
void ack_lease(struct packet *, struct lease *, unsigned int, TIME, char *, int, struct host_decl *)
struct interface_info * interface
u_int8_t hbuf[HARDWARE_ADDR_LEN+1]
struct ipv6_pool ** pools
option_code_hash_t * code_hash
int can_unicast_without_arp(struct interface_info *)
struct executable_statement * on_commit
const unsigned char * data
struct binding_scope * scope
unsigned char options[DHCP_MAX_OPTION_LEN]