Indicate that client_state_t and client_config_t pointer args
cannot ever be null. Could possibly improve code generation, and makes the intention clear.
This commit is contained in:
parent
b6554c2931
commit
cc806acc0b
70
src/arp.c
70
src/arp.c
@ -151,7 +151,7 @@ static int get_arp_basic_socket(void)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_arp_defense_socket(struct client_state_t *cs)
|
static int get_arp_defense_socket(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
@ -172,7 +172,7 @@ static int get_arp_defense_socket(struct client_state_t *cs)
|
|||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int arp_open_fd(struct client_state_t *cs, arp_state_t state)
|
static int arp_open_fd(struct client_state_t cs[static 1], arp_state_t state)
|
||||||
{
|
{
|
||||||
if (cs->arpFd >= 0) {
|
if (cs->arpFd >= 0) {
|
||||||
log_warning("%s: (%s) called but fd already exists",
|
log_warning("%s: (%s) called but fd already exists",
|
||||||
@ -199,7 +199,7 @@ static int arp_open_fd(struct client_state_t *cs, arp_state_t state)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_min_close_fd(struct client_state_t *cs)
|
static void arp_min_close_fd(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (cs->arpFd < 0)
|
if (cs->arpFd < 0)
|
||||||
return;
|
return;
|
||||||
@ -209,7 +209,7 @@ static void arp_min_close_fd(struct client_state_t *cs)
|
|||||||
garp.state = AS_NONE;
|
garp.state = AS_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_switch_state(struct client_state_t *cs, arp_state_t state)
|
static void arp_switch_state(struct client_state_t cs[static 1], arp_state_t state)
|
||||||
{
|
{
|
||||||
if (garp.state == state || garp.state >= AS_MAX)
|
if (garp.state == state || garp.state >= AS_MAX)
|
||||||
return;
|
return;
|
||||||
@ -228,21 +228,21 @@ static void arp_switch_state(struct client_state_t *cs, arp_state_t state)
|
|||||||
garp.state = state;
|
garp.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
void arp_close_fd(struct client_state_t *cs)
|
void arp_close_fd(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
arp_min_close_fd(cs);
|
arp_min_close_fd(cs);
|
||||||
for (int i = 0; i < AS_MAX; ++i)
|
for (int i = 0; i < AS_MAX; ++i)
|
||||||
garp.wake_ts[i] = -1;
|
garp.wake_ts[i] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_reopen_fd(struct client_state_t *cs)
|
static void arp_reopen_fd(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
arp_state_t prev_state = garp.state;
|
arp_state_t prev_state = garp.state;
|
||||||
arp_min_close_fd(cs);
|
arp_min_close_fd(cs);
|
||||||
arp_switch_state(cs, prev_state);
|
arp_switch_state(cs, prev_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int arp_send(struct client_state_t *cs, struct arpMsg *arp)
|
static int arp_send(struct client_state_t cs[static 1], struct arpMsg *arp)
|
||||||
{
|
{
|
||||||
struct sockaddr_ll addr = {
|
struct sockaddr_ll addr = {
|
||||||
.sll_family = AF_PACKET,
|
.sll_family = AF_PACKET,
|
||||||
@ -292,7 +292,7 @@ carrier_down:
|
|||||||
memcpy(arp.smac, client_config.arp, 6)
|
memcpy(arp.smac, client_config.arp, 6)
|
||||||
|
|
||||||
// Returns 0 on success, -1 on failure.
|
// Returns 0 on success, -1 on failure.
|
||||||
static int arp_ping(struct client_state_t *cs, uint32_t test_ip)
|
static int arp_ping(struct client_state_t cs[static 1], uint32_t test_ip)
|
||||||
{
|
{
|
||||||
BASE_ARPMSG();
|
BASE_ARPMSG();
|
||||||
memcpy(arp.sip4, &cs->clientAddr, sizeof cs->clientAddr);
|
memcpy(arp.sip4, &cs->clientAddr, sizeof cs->clientAddr);
|
||||||
@ -305,7 +305,7 @@ static int arp_ping(struct client_state_t *cs, uint32_t test_ip)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns 0 on success, -1 on failure.
|
// Returns 0 on success, -1 on failure.
|
||||||
static int arp_ip_anon_ping(struct client_state_t *cs, uint32_t test_ip)
|
static int arp_ip_anon_ping(struct client_state_t cs[static 1], uint32_t test_ip)
|
||||||
{
|
{
|
||||||
BASE_ARPMSG();
|
BASE_ARPMSG();
|
||||||
memcpy(arp.dip4, &test_ip, sizeof test_ip);
|
memcpy(arp.dip4, &test_ip, sizeof test_ip);
|
||||||
@ -318,7 +318,7 @@ static int arp_ip_anon_ping(struct client_state_t *cs, uint32_t test_ip)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int arp_announcement(struct client_state_t *cs)
|
static int arp_announcement(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
BASE_ARPMSG();
|
BASE_ARPMSG();
|
||||||
memcpy(arp.sip4, &cs->clientAddr, 4);
|
memcpy(arp.sip4, &cs->clientAddr, 4);
|
||||||
@ -332,7 +332,7 @@ static int arp_announcement(struct client_state_t *cs)
|
|||||||
#undef BASE_ARPMSG
|
#undef BASE_ARPMSG
|
||||||
|
|
||||||
// Callable from DS_REQUESTING, DS_RENEWING, or DS_REBINDING via an_packet()
|
// Callable from DS_REQUESTING, DS_RENEWING, or DS_REBINDING via an_packet()
|
||||||
int arp_check(struct client_state_t *cs, struct dhcpmsg *packet)
|
int arp_check(struct client_state_t cs[static 1], struct dhcpmsg *packet)
|
||||||
{
|
{
|
||||||
memcpy(&garp.dhcp_packet, packet, sizeof (struct dhcpmsg));
|
memcpy(&garp.dhcp_packet, packet, sizeof (struct dhcpmsg));
|
||||||
arp_switch_state(cs, AS_COLLISION_CHECK);
|
arp_switch_state(cs, AS_COLLISION_CHECK);
|
||||||
@ -348,7 +348,7 @@ int arp_check(struct client_state_t *cs, struct dhcpmsg *packet)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Callable only from DS_BOUND via state.c:ifup_action().
|
// Callable only from DS_BOUND via state.c:ifup_action().
|
||||||
int arp_gw_check(struct client_state_t *cs)
|
int arp_gw_check(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (garp.state == AS_GW_CHECK) // Guard against state bounce.
|
if (garp.state == AS_GW_CHECK) // Guard against state bounce.
|
||||||
return 0;
|
return 0;
|
||||||
@ -371,7 +371,7 @@ int arp_gw_check(struct client_state_t *cs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Should only be called from DS_BOUND state.
|
// Should only be called from DS_BOUND state.
|
||||||
static int arp_get_gw_hwaddr(struct client_state_t *cs)
|
static int arp_get_gw_hwaddr(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (cs->dhcpState != DS_BOUND)
|
if (cs->dhcpState != DS_BOUND)
|
||||||
log_error("arp_get_gw_hwaddr: called when state != DS_BOUND");
|
log_error("arp_get_gw_hwaddr: called when state != DS_BOUND");
|
||||||
@ -396,7 +396,7 @@ static int arp_get_gw_hwaddr(struct client_state_t *cs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_failed(struct client_state_t *cs)
|
static void arp_failed(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
log_line("%s: arp: Offered address is in use. Declining.",
|
log_line("%s: arp: Offered address is in use. Declining.",
|
||||||
client_config.interface);
|
client_config.interface);
|
||||||
@ -406,13 +406,13 @@ static void arp_failed(struct client_state_t *cs)
|
|||||||
0 : RATE_LIMIT_INTERVAL);
|
0 : RATE_LIMIT_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_gw_failed(struct client_state_t *cs)
|
static void arp_gw_failed(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
garp.wake_ts[AS_GW_CHECK] = -1;
|
garp.wake_ts[AS_GW_CHECK] = -1;
|
||||||
reinit_selecting(cs, 0);
|
reinit_selecting(cs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int act_if_arp_gw_failed(struct client_state_t *cs)
|
static int act_if_arp_gw_failed(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (garp.send_stats[ASEND_GW_PING].count >= garp.gw_check_initpings + 6) {
|
if (garp.send_stats[ASEND_GW_PING].count >= garp.gw_check_initpings + 6) {
|
||||||
if (garp.router_replied && !garp.server_replied)
|
if (garp.router_replied && !garp.server_replied)
|
||||||
@ -430,12 +430,12 @@ static int act_if_arp_gw_failed(struct client_state_t *cs)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void arp_set_defense_mode(struct client_state_t *cs)
|
void arp_set_defense_mode(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
arp_switch_state(cs, AS_DEFENSE);
|
arp_switch_state(cs, AS_DEFENSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void arp_success(struct client_state_t *cs)
|
void arp_success(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
char clibuf[INET_ADDRSTRLEN];
|
char clibuf[INET_ADDRSTRLEN];
|
||||||
struct in_addr temp_addr = {.s_addr = garp.dhcp_packet.yiaddr};
|
struct in_addr temp_addr = {.s_addr = garp.dhcp_packet.yiaddr};
|
||||||
@ -463,7 +463,7 @@ void arp_success(struct client_state_t *cs)
|
|||||||
background();
|
background();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_gw_success(struct client_state_t *cs)
|
static void arp_gw_success(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
log_line("%s: arp: Network seems unchanged. Resuming normal operation.",
|
log_line("%s: arp: Network seems unchanged. Resuming normal operation.",
|
||||||
client_config.interface);
|
client_config.interface);
|
||||||
@ -508,7 +508,7 @@ static int arp_validate_bpf(struct arpMsg *am)
|
|||||||
|
|
||||||
// ARP validation functions that will be performed by the BPF if it is
|
// ARP validation functions that will be performed by the BPF if it is
|
||||||
// installed.
|
// installed.
|
||||||
static int arp_validate_bpf_defense(struct client_state_t *cs,
|
static int arp_validate_bpf_defense(struct client_state_t cs[static 1],
|
||||||
struct arpMsg *am)
|
struct arpMsg *am)
|
||||||
{
|
{
|
||||||
if (memcmp(am->sip4, &cs->clientAddr, 4))
|
if (memcmp(am->sip4, &cs->clientAddr, 4))
|
||||||
@ -529,14 +529,14 @@ static int arp_is_query_reply(struct arpMsg *am)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int arp_gen_probe_wait(struct client_state_t *cs)
|
static int arp_gen_probe_wait(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
// This is not a uniform distribution but it doesn't matter here.
|
// This is not a uniform distribution but it doesn't matter here.
|
||||||
return arp_probe_min + (nk_random_u32(&cs->rnd32_state) & 0x7fffffffu)
|
return arp_probe_min + (nk_random_u32(&cs->rnd32_state) & 0x7fffffffu)
|
||||||
% (arp_probe_max - arp_probe_min);
|
% (arp_probe_max - arp_probe_min);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_defense_timeout(struct client_state_t *cs, long long nowts)
|
static void arp_defense_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
(void)nowts; // Suppress warning; parameter necessary but unused.
|
(void)nowts; // Suppress warning; parameter necessary but unused.
|
||||||
if (garp.wake_ts[AS_DEFENSE] != -1) {
|
if (garp.wake_ts[AS_DEFENSE] != -1) {
|
||||||
@ -546,7 +546,7 @@ static void arp_defense_timeout(struct client_state_t *cs, long long nowts)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_gw_check_timeout(struct client_state_t *cs, long long nowts)
|
static void arp_gw_check_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
arp_defense_timeout(cs, nowts);
|
arp_defense_timeout(cs, nowts);
|
||||||
|
|
||||||
@ -575,14 +575,14 @@ static void arp_gw_check_timeout(struct client_state_t *cs, long long nowts)
|
|||||||
garp.send_stats[ASEND_GW_PING].ts + ARP_RETRANS_DELAY;
|
garp.send_stats[ASEND_GW_PING].ts + ARP_RETRANS_DELAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_do_gw_query_done(struct client_state_t *cs)
|
static void arp_do_gw_query_done(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
garp.wake_ts[AS_GW_QUERY] = -1;
|
garp.wake_ts[AS_GW_QUERY] = -1;
|
||||||
arp_switch_state(cs, AS_DEFENSE);
|
arp_switch_state(cs, AS_DEFENSE);
|
||||||
arp_announcement(cs); // Do a second announcement.
|
arp_announcement(cs); // Do a second announcement.
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_gw_query_timeout(struct client_state_t *cs, long long nowts)
|
static void arp_gw_query_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
arp_defense_timeout(cs, nowts);
|
arp_defense_timeout(cs, nowts);
|
||||||
|
|
||||||
@ -609,7 +609,7 @@ static void arp_gw_query_timeout(struct client_state_t *cs, long long nowts)
|
|||||||
garp.send_stats[ASEND_GW_PING].ts + ARP_RETRANS_DELAY;
|
garp.send_stats[ASEND_GW_PING].ts + ARP_RETRANS_DELAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_collision_timeout(struct client_state_t *cs, long long nowts)
|
static void arp_collision_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
arp_defense_timeout(cs, nowts);
|
arp_defense_timeout(cs, nowts);
|
||||||
|
|
||||||
@ -632,7 +632,7 @@ static void arp_collision_timeout(struct client_state_t *cs, long long nowts)
|
|||||||
garp.send_stats[ASEND_COLLISION_CHECK].ts + garp.probe_wait_time;
|
garp.send_stats[ASEND_COLLISION_CHECK].ts + garp.probe_wait_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_do_defense(struct client_state_t *cs)
|
static void arp_do_defense(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
// Even though the BPF will usually catch this case, sometimes there are
|
// Even though the BPF will usually catch this case, sometimes there are
|
||||||
// packets still in the socket buffer that arrived before the defense
|
// packets still in the socket buffer that arrived before the defense
|
||||||
@ -660,7 +660,7 @@ static void arp_do_defense(struct client_state_t *cs)
|
|||||||
garp.last_conflict_ts = nowts;
|
garp.last_conflict_ts = nowts;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_do_gw_query(struct client_state_t *cs)
|
static void arp_do_gw_query(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (!arp_is_query_reply(&garp.reply)) {
|
if (!arp_is_query_reply(&garp.reply)) {
|
||||||
arp_do_defense(cs);
|
arp_do_defense(cs);
|
||||||
@ -694,7 +694,7 @@ server_is_router:
|
|||||||
arp_do_defense(cs);
|
arp_do_defense(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_do_collision_check(struct client_state_t *cs)
|
static void arp_do_collision_check(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (!arp_is_query_reply(&garp.reply))
|
if (!arp_is_query_reply(&garp.reply))
|
||||||
return;
|
return;
|
||||||
@ -708,7 +708,7 @@ static void arp_do_collision_check(struct client_state_t *cs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_do_gw_check(struct client_state_t *cs)
|
static void arp_do_gw_check(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (!arp_is_query_reply(&garp.reply))
|
if (!arp_is_query_reply(&garp.reply))
|
||||||
return;
|
return;
|
||||||
@ -742,7 +742,7 @@ server_is_router:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void arp_do_invalid(struct client_state_t *cs)
|
static void arp_do_invalid(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
log_error("%s: (%s) called in invalid state %u", client_config.interface,
|
log_error("%s: (%s) called in invalid state %u", client_config.interface,
|
||||||
__func__, garp.state);
|
__func__, garp.state);
|
||||||
@ -750,8 +750,8 @@ static void arp_do_invalid(struct client_state_t *cs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*packet_fn)(struct client_state_t *cs);
|
void (*packet_fn)(struct client_state_t cs[static 1]);
|
||||||
void (*timeout_fn)(struct client_state_t *cs, long long nowts);
|
void (*timeout_fn)(struct client_state_t cs[static 1], long long nowts);
|
||||||
} arp_state_fn_t;
|
} arp_state_fn_t;
|
||||||
|
|
||||||
static const arp_state_fn_t arp_states[] = {
|
static const arp_state_fn_t arp_states[] = {
|
||||||
@ -763,7 +763,7 @@ static const arp_state_fn_t arp_states[] = {
|
|||||||
{ arp_do_invalid, 0 }, // AS_MAX
|
{ arp_do_invalid, 0 }, // AS_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
void handle_arp_response(struct client_state_t *cs)
|
void handle_arp_response(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
ssize_t r = 0;
|
ssize_t r = 0;
|
||||||
if (garp.reply_offset < sizeof garp.reply) {
|
if (garp.reply_offset < sizeof garp.reply) {
|
||||||
@ -804,7 +804,7 @@ void handle_arp_response(struct client_state_t *cs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Perform retransmission if necessary.
|
// Perform retransmission if necessary.
|
||||||
void handle_arp_timeout(struct client_state_t *cs, long long nowts)
|
void handle_arp_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
if (arp_states[garp.state].timeout_fn)
|
if (arp_states[garp.state].timeout_fn)
|
||||||
arp_states[garp.state].timeout_fn(cs, nowts);
|
arp_states[garp.state].timeout_fn(cs, nowts);
|
||||||
|
14
src/arp.h
14
src/arp.h
@ -60,13 +60,13 @@ extern int arp_probe_max;
|
|||||||
|
|
||||||
void set_arp_relentless_def(bool v);
|
void set_arp_relentless_def(bool v);
|
||||||
void arp_reset_send_stats(void);
|
void arp_reset_send_stats(void);
|
||||||
void arp_close_fd(struct client_state_t *cs);
|
void arp_close_fd(struct client_state_t cs[static 1]);
|
||||||
int arp_check(struct client_state_t *cs, struct dhcpmsg *packet);
|
int arp_check(struct client_state_t cs[static 1], struct dhcpmsg *packet);
|
||||||
int arp_gw_check(struct client_state_t *cs);
|
int arp_gw_check(struct client_state_t cs[static 1]);
|
||||||
void arp_set_defense_mode(struct client_state_t *cs);
|
void arp_set_defense_mode(struct client_state_t cs[static 1]);
|
||||||
void arp_success(struct client_state_t *cs);
|
void arp_success(struct client_state_t cs[static 1]);
|
||||||
void handle_arp_response(struct client_state_t *cs);
|
void handle_arp_response(struct client_state_t cs[static 1]);
|
||||||
void handle_arp_timeout(struct client_state_t *cs, long long nowts);
|
void handle_arp_timeout(struct client_state_t cs[static 1], long long nowts);
|
||||||
long long arp_get_wake_ts(void);
|
long long arp_get_wake_ts(void);
|
||||||
|
|
||||||
#endif /* ARP_H_ */
|
#endif /* ARP_H_ */
|
||||||
|
28
src/dhcp.c
28
src/dhcp.c
@ -50,7 +50,7 @@
|
|||||||
#include "options.h"
|
#include "options.h"
|
||||||
#include "sockd.h"
|
#include "sockd.h"
|
||||||
|
|
||||||
static int get_udp_unicast_socket(struct client_state_t *cs)
|
static int get_udp_unicast_socket(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
char buf[32];
|
char buf[32];
|
||||||
buf[0] = 'u';
|
buf[0] = 'u';
|
||||||
@ -63,7 +63,7 @@ static int get_raw_broadcast_socket(void)
|
|||||||
return request_sockd_fd("s", 1, NULL);
|
return request_sockd_fd("s", 1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_raw_listen_socket(struct client_state_t *cs)
|
static int get_raw_listen_socket(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
char resp;
|
char resp;
|
||||||
int fd = request_sockd_fd("L", 1, &resp);
|
int fd = request_sockd_fd("L", 1, &resp);
|
||||||
@ -77,7 +77,7 @@ static int get_raw_listen_socket(struct client_state_t *cs)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Unicast a DHCP message using a UDP socket.
|
// Unicast a DHCP message using a UDP socket.
|
||||||
static ssize_t send_dhcp_unicast(struct client_state_t *cs,
|
static ssize_t send_dhcp_unicast(struct client_state_t cs[static 1],
|
||||||
struct dhcpmsg *payload)
|
struct dhcpmsg *payload)
|
||||||
{
|
{
|
||||||
ssize_t ret = -1;
|
ssize_t ret = -1;
|
||||||
@ -179,7 +179,7 @@ static int get_raw_packet_validate_bpf(struct ip_udp_dhcp_packet *packet)
|
|||||||
|
|
||||||
// Read a packet from a raw socket. Returns -1 on fatal error, -2 on
|
// Read a packet from a raw socket. Returns -1 on fatal error, -2 on
|
||||||
// transient error.
|
// transient error.
|
||||||
static ssize_t get_raw_packet(struct client_state_t *cs,
|
static ssize_t get_raw_packet(struct client_state_t cs[static 1],
|
||||||
struct dhcpmsg *payload,
|
struct dhcpmsg *payload,
|
||||||
uint32_t *srcaddr)
|
uint32_t *srcaddr)
|
||||||
{
|
{
|
||||||
@ -321,7 +321,7 @@ carrier_down:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void start_dhcp_listen(struct client_state_t *cs)
|
void start_dhcp_listen(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (cs->listenFd >= 0)
|
if (cs->listenFd >= 0)
|
||||||
return;
|
return;
|
||||||
@ -332,7 +332,7 @@ void start_dhcp_listen(struct client_state_t *cs)
|
|||||||
epoll_add(cs->epollFd, cs->listenFd);
|
epoll_add(cs->epollFd, cs->listenFd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void stop_dhcp_listen(struct client_state_t *cs)
|
void stop_dhcp_listen(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (cs->listenFd < 0)
|
if (cs->listenFd < 0)
|
||||||
return;
|
return;
|
||||||
@ -341,7 +341,7 @@ void stop_dhcp_listen(struct client_state_t *cs)
|
|||||||
cs->listenFd = -1;
|
cs->listenFd = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int validate_dhcp_packet(struct client_state_t *cs, size_t len,
|
static int validate_dhcp_packet(struct client_state_t cs[static 1], size_t len,
|
||||||
struct dhcpmsg *packet, uint8_t *msgtype)
|
struct dhcpmsg *packet, uint8_t *msgtype)
|
||||||
{
|
{
|
||||||
if (len < offsetof(struct dhcpmsg, options)) {
|
if (len < offsetof(struct dhcpmsg, options)) {
|
||||||
@ -393,7 +393,7 @@ static int validate_dhcp_packet(struct client_state_t *cs, size_t len,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_packet(struct client_state_t *cs)
|
void handle_packet(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (cs->listenFd < 0)
|
if (cs->listenFd < 0)
|
||||||
return;
|
return;
|
||||||
@ -434,7 +434,7 @@ static struct dhcpmsg init_packet(char type, uint32_t xid)
|
|||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t send_discover(struct client_state_t *cs)
|
ssize_t send_discover(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
struct dhcpmsg packet = init_packet(DHCPDISCOVER, cs->xid);
|
struct dhcpmsg packet = init_packet(DHCPDISCOVER, cs->xid);
|
||||||
if (cs->clientAddr)
|
if (cs->clientAddr)
|
||||||
@ -447,7 +447,7 @@ ssize_t send_discover(struct client_state_t *cs)
|
|||||||
return send_dhcp_raw(&packet);
|
return send_dhcp_raw(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t send_selecting(struct client_state_t *cs)
|
ssize_t send_selecting(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
char clibuf[INET_ADDRSTRLEN];
|
char clibuf[INET_ADDRSTRLEN];
|
||||||
struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid);
|
struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid);
|
||||||
@ -464,7 +464,7 @@ ssize_t send_selecting(struct client_state_t *cs)
|
|||||||
return send_dhcp_raw(&packet);
|
return send_dhcp_raw(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t send_renew(struct client_state_t *cs)
|
ssize_t send_renew(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid);
|
struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid);
|
||||||
packet.ciaddr = cs->clientAddr;
|
packet.ciaddr = cs->clientAddr;
|
||||||
@ -476,7 +476,7 @@ ssize_t send_renew(struct client_state_t *cs)
|
|||||||
return send_dhcp_unicast(cs, &packet);
|
return send_dhcp_unicast(cs, &packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t send_rebind(struct client_state_t *cs)
|
ssize_t send_rebind(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid);
|
struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid);
|
||||||
packet.ciaddr = cs->clientAddr;
|
packet.ciaddr = cs->clientAddr;
|
||||||
@ -489,7 +489,7 @@ ssize_t send_rebind(struct client_state_t *cs)
|
|||||||
return send_dhcp_raw(&packet);
|
return send_dhcp_raw(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t send_decline(struct client_state_t *cs, uint32_t server)
|
ssize_t send_decline(struct client_state_t cs[static 1], uint32_t server)
|
||||||
{
|
{
|
||||||
struct dhcpmsg packet = init_packet(DHCPDECLINE, cs->xid);
|
struct dhcpmsg packet = init_packet(DHCPDECLINE, cs->xid);
|
||||||
add_option_reqip(&packet, cs->clientAddr);
|
add_option_reqip(&packet, cs->clientAddr);
|
||||||
@ -498,7 +498,7 @@ ssize_t send_decline(struct client_state_t *cs, uint32_t server)
|
|||||||
return send_dhcp_raw(&packet);
|
return send_dhcp_raw(&packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t send_release(struct client_state_t *cs)
|
ssize_t send_release(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
struct dhcpmsg packet = init_packet(DHCPRELEASE,
|
struct dhcpmsg packet = init_packet(DHCPRELEASE,
|
||||||
nk_random_u32(&cs->rnd32_state));
|
nk_random_u32(&cs->rnd32_state));
|
||||||
|
18
src/dhcp.h
18
src/dhcp.h
@ -81,15 +81,15 @@ struct udp_dhcp_packet {
|
|||||||
struct dhcpmsg data;
|
struct dhcpmsg data;
|
||||||
};
|
};
|
||||||
|
|
||||||
void start_dhcp_listen(struct client_state_t *cs);
|
void start_dhcp_listen(struct client_state_t cs[static 1]);
|
||||||
void stop_dhcp_listen(struct client_state_t *cs);
|
void stop_dhcp_listen(struct client_state_t cs[static 1]);
|
||||||
void handle_packet(struct client_state_t *cs);
|
void handle_packet(struct client_state_t cs[static 1]);
|
||||||
ssize_t send_discover(struct client_state_t *cs);
|
ssize_t send_discover(struct client_state_t cs[static 1]);
|
||||||
ssize_t send_selecting(struct client_state_t *cs);
|
ssize_t send_selecting(struct client_state_t cs[static 1]);
|
||||||
ssize_t send_renew(struct client_state_t *cs);
|
ssize_t send_renew(struct client_state_t cs[static 1]);
|
||||||
ssize_t send_rebind(struct client_state_t *cs);
|
ssize_t send_rebind(struct client_state_t cs[static 1]);
|
||||||
ssize_t send_decline(struct client_state_t *cs, uint32_t server);
|
ssize_t send_decline(struct client_state_t cs[static 1], uint32_t server);
|
||||||
ssize_t send_release(struct client_state_t *cs);
|
ssize_t send_release(struct client_state_t cs[static 1]);
|
||||||
|
|
||||||
int check_carrier(int fd);
|
int check_carrier(int fd);
|
||||||
|
|
||||||
|
@ -156,7 +156,7 @@ static size_t generate_iaid(struct nk_random_state_u32 *s, char *dest,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Failures are all fatal.
|
// Failures are all fatal.
|
||||||
void get_clientid(struct client_state_t *cs, struct client_config_t *cc)
|
void get_clientid(struct client_state_t cs[static 1], struct client_config_t cc[static 1])
|
||||||
{
|
{
|
||||||
if (cc->clientid_len > 0)
|
if (cc->clientid_len > 0)
|
||||||
return;
|
return;
|
||||||
|
@ -30,6 +30,6 @@
|
|||||||
|
|
||||||
#include "ndhc.h"
|
#include "ndhc.h"
|
||||||
|
|
||||||
void get_clientid(struct client_state_t *cs, struct client_config_t *cc);
|
void get_clientid(struct client_state_t cs[static 1], struct client_config_t cc[static 1]);
|
||||||
|
|
||||||
#endif /* NJK_NDHC_DUIAID_H_ */
|
#endif /* NJK_NDHC_DUIAID_H_ */
|
||||||
|
@ -47,7 +47,7 @@
|
|||||||
|
|
||||||
static struct dhcpmsg cfg_packet; // Copy of the current configuration packet.
|
static struct dhcpmsg cfg_packet; // Copy of the current configuration packet.
|
||||||
|
|
||||||
static int ifcmd_raw(char *buf, size_t buflen, char *optname,
|
static int ifcmd_raw(char buf[static 1], size_t buflen, char *optname,
|
||||||
char *optdata, ssize_t optlen)
|
char *optdata, ssize_t optlen)
|
||||||
{
|
{
|
||||||
if (!optdata) {
|
if (!optdata) {
|
||||||
@ -77,13 +77,13 @@ static int ifcmd_raw(char *buf, size_t buflen, char *optname,
|
|||||||
return olen;
|
return olen;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ifcmd_bytes(char *buf, size_t buflen, char *optname,
|
static int ifcmd_bytes(char buf[static 1], size_t buflen, char *optname,
|
||||||
uint8_t *optdata, ssize_t optlen)
|
uint8_t *optdata, ssize_t optlen)
|
||||||
{
|
{
|
||||||
return ifcmd_raw(buf, buflen, optname, (char *)optdata, optlen);
|
return ifcmd_raw(buf, buflen, optname, (char *)optdata, optlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ifcmd_u8(char *buf, size_t buflen, char *optname,
|
static int ifcmd_u8(char buf[static 1], size_t buflen, char *optname,
|
||||||
uint8_t *optdata, ssize_t optlen)
|
uint8_t *optdata, ssize_t optlen)
|
||||||
{
|
{
|
||||||
if (!optdata || optlen < 1)
|
if (!optdata || optlen < 1)
|
||||||
@ -96,7 +96,7 @@ static int ifcmd_u8(char *buf, size_t buflen, char *optname,
|
|||||||
return ifcmd_raw(buf, buflen, optname, numbuf, strlen(numbuf));
|
return ifcmd_raw(buf, buflen, optname, numbuf, strlen(numbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ifcmd_u16(char *buf, size_t buflen, char *optname,
|
static int ifcmd_u16(char buf[static 1], size_t buflen, char *optname,
|
||||||
uint8_t *optdata, ssize_t optlen)
|
uint8_t *optdata, ssize_t optlen)
|
||||||
{
|
{
|
||||||
if (!optdata || optlen < 2)
|
if (!optdata || optlen < 2)
|
||||||
@ -111,7 +111,7 @@ static int ifcmd_u16(char *buf, size_t buflen, char *optname,
|
|||||||
return ifcmd_raw(buf, buflen, optname, numbuf, strlen(numbuf));
|
return ifcmd_raw(buf, buflen, optname, numbuf, strlen(numbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ifcmd_s32(char *buf, size_t buflen, char *optname,
|
static int ifcmd_s32(char buf[static 1], size_t buflen, char *optname,
|
||||||
uint8_t *optdata, ssize_t optlen)
|
uint8_t *optdata, ssize_t optlen)
|
||||||
{
|
{
|
||||||
if (!optdata || optlen < 4)
|
if (!optdata || optlen < 4)
|
||||||
@ -126,7 +126,7 @@ static int ifcmd_s32(char *buf, size_t buflen, char *optname,
|
|||||||
return ifcmd_raw(buf, buflen, optname, numbuf, strlen(numbuf));
|
return ifcmd_raw(buf, buflen, optname, numbuf, strlen(numbuf));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ifcmd_ip(char *buf, size_t buflen, char *optname,
|
static int ifcmd_ip(char buf[static 1], size_t buflen, char *optname,
|
||||||
uint8_t *optdata, ssize_t optlen)
|
uint8_t *optdata, ssize_t optlen)
|
||||||
{
|
{
|
||||||
if (!optdata || optlen < 4)
|
if (!optdata || optlen < 4)
|
||||||
@ -184,7 +184,7 @@ static int ifchd_cmd(char *b, size_t bl, uint8_t *od, ssize_t ol, uint8_t code)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ifchwrite(struct client_state_t *cs, const char *buf, size_t count)
|
static void ifchwrite(struct client_state_t cs[static 1], const char buf[static 1], size_t count)
|
||||||
{
|
{
|
||||||
cs->ifchWorking = 1;
|
cs->ifchWorking = 1;
|
||||||
ssize_t r = safe_write(ifchSock[0], buf, count);
|
ssize_t r = safe_write(ifchSock[0], buf, count);
|
||||||
@ -195,7 +195,7 @@ static void ifchwrite(struct client_state_t *cs, const char *buf, size_t count)
|
|||||||
log_line("%s: Sent to ifchd: '%s'", client_config.interface, buf);
|
log_line("%s: Sent to ifchd: '%s'", client_config.interface, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ifchange_deconfig(struct client_state_t *cs)
|
void ifchange_deconfig(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ static size_t send_cmd(char *out, size_t olen, struct dhcpmsg *packet,
|
|||||||
return r > 0 ? r : 0;
|
return r > 0 ? r : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ifchange_bind(struct client_state_t *cs, struct dhcpmsg *packet)
|
void ifchange_bind(struct client_state_t cs[static 1], struct dhcpmsg *packet)
|
||||||
{
|
{
|
||||||
char buf[2048];
|
char buf[2048];
|
||||||
size_t bo;
|
size_t bo;
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
#ifndef IFCHANGE_H_
|
#ifndef IFCHANGE_H_
|
||||||
#define IFCHANGE_H_
|
#define IFCHANGE_H_
|
||||||
|
|
||||||
void ifchange_bind(struct client_state_t *cs, struct dhcpmsg *packet);
|
void ifchange_bind(struct client_state_t cs[static 1], struct dhcpmsg *packet);
|
||||||
void ifchange_deconfig(struct client_state_t *cs);
|
void ifchange_deconfig(struct client_state_t cs[static 1]);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -76,7 +76,7 @@
|
|||||||
|
|
||||||
%% write data;
|
%% write data;
|
||||||
|
|
||||||
static void perform_ip4set(const char *buf, size_t len)
|
static void perform_ip4set(const char buf[static 1], size_t len)
|
||||||
{
|
{
|
||||||
char ip4_addr[INET_ADDRSTRLEN];
|
char ip4_addr[INET_ADDRSTRLEN];
|
||||||
char ip4_subnet[INET_ADDRSTRLEN];
|
char ip4_subnet[INET_ADDRSTRLEN];
|
||||||
|
@ -67,7 +67,7 @@ int allow_hostname = 0;
|
|||||||
uid_t ifch_uid = 0;
|
uid_t ifch_uid = 0;
|
||||||
gid_t ifch_gid = 0;
|
gid_t ifch_gid = 0;
|
||||||
|
|
||||||
static void writeordie(int fd, const char *buf, size_t len)
|
static void writeordie(int fd, const char buf[static 1], size_t len)
|
||||||
{
|
{
|
||||||
ssize_t r = safe_write(fd, buf, len);
|
ssize_t r = safe_write(fd, buf, len);
|
||||||
if (r < 0 || (size_t)r != len)
|
if (r < 0 || (size_t)r != len)
|
||||||
|
@ -91,7 +91,7 @@ static void nl_process_msgs(const struct nlmsghdr *nlh, void *data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_nl_message(struct client_state_t *cs)
|
void handle_nl_message(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
char nlbuf[8192];
|
char nlbuf[8192];
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
@ -40,7 +40,7 @@ enum {
|
|||||||
IFS_REMOVED
|
IFS_REMOVED
|
||||||
};
|
};
|
||||||
|
|
||||||
void handle_nl_message(struct client_state_t *cs);
|
void handle_nl_message(struct client_state_t cs[static 1]);
|
||||||
int nl_getifdata(void);
|
int nl_getifdata(void);
|
||||||
|
|
||||||
#endif /* NK_NETLINK_H_ */
|
#endif /* NK_NETLINK_H_ */
|
||||||
|
4
src/nl.c
4
src/nl.c
@ -81,7 +81,7 @@ void nl_rtattr_parse(const struct nlmsghdr *nlh, size_t offset,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t nl_recv_buf(int fd, char *buf, size_t blen)
|
ssize_t nl_recv_buf(int fd, char buf[static 1], size_t blen)
|
||||||
{
|
{
|
||||||
struct sockaddr_nl addr;
|
struct sockaddr_nl addr;
|
||||||
struct iovec iov = {
|
struct iovec iov = {
|
||||||
@ -114,7 +114,7 @@ ssize_t nl_recv_buf(int fd, char *buf, size_t blen)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nl_foreach_nlmsg(char *buf, size_t blen, uint32_t seq, uint32_t portid,
|
int nl_foreach_nlmsg(char buf[static 1], size_t blen, uint32_t seq, uint32_t portid,
|
||||||
nlmsg_foreach_fn pfn, void *fnarg)
|
nlmsg_foreach_fn pfn, void *fnarg)
|
||||||
{
|
{
|
||||||
const struct nlmsghdr *nlh = (const struct nlmsghdr *)buf;
|
const struct nlmsghdr *nlh = (const struct nlmsghdr *)buf;
|
||||||
|
4
src/nl.h
4
src/nl.h
@ -48,10 +48,10 @@ typedef int (*nl_rtattr_parse_fn)(struct rtattr *attr, int type, void *data);
|
|||||||
void nl_rtattr_parse(const struct nlmsghdr *nlh, size_t offset,
|
void nl_rtattr_parse(const struct nlmsghdr *nlh, size_t offset,
|
||||||
nl_rtattr_parse_fn workfn, void *data);
|
nl_rtattr_parse_fn workfn, void *data);
|
||||||
|
|
||||||
ssize_t nl_recv_buf(int fd, char *buf, size_t blen);
|
ssize_t nl_recv_buf(int fd, char buf[static 1], size_t blen);
|
||||||
|
|
||||||
typedef void (*nlmsg_foreach_fn)(const struct nlmsghdr *, void *);
|
typedef void (*nlmsg_foreach_fn)(const struct nlmsghdr *, void *);
|
||||||
int nl_foreach_nlmsg(char *buf, size_t blen, uint32_t seq,
|
int nl_foreach_nlmsg(char buf[static 1], size_t blen, uint32_t seq,
|
||||||
uint32_t portid,
|
uint32_t portid,
|
||||||
nlmsg_foreach_fn pfn, void *fnarg);
|
nlmsg_foreach_fn pfn, void *fnarg);
|
||||||
int nl_sendgetlinks(int fd, int seq);
|
int nl_sendgetlinks(int fd, int seq);
|
||||||
|
@ -34,7 +34,7 @@
|
|||||||
|
|
||||||
#include "options.h"
|
#include "options.h"
|
||||||
|
|
||||||
static int do_overload_value(const uint8_t *buf, ssize_t blen, int overload)
|
static int do_overload_value(const uint8_t buf[static 1], ssize_t blen, int overload)
|
||||||
{
|
{
|
||||||
ssize_t i = 0;
|
ssize_t i = 0;
|
||||||
while (i < blen) {
|
while (i < blen) {
|
||||||
|
@ -67,7 +67,7 @@ uid_t sockd_uid = 0;
|
|||||||
gid_t sockd_gid = 0;
|
gid_t sockd_gid = 0;
|
||||||
|
|
||||||
// Interface to make requests of sockd. Called from ndhc process.
|
// Interface to make requests of sockd. Called from ndhc process.
|
||||||
int request_sockd_fd(char *buf, size_t buflen, char *response)
|
int request_sockd_fd(char buf[static 1], size_t buflen, char *response)
|
||||||
{
|
{
|
||||||
if (!buflen)
|
if (!buflen)
|
||||||
return -1;
|
return -1;
|
||||||
@ -477,7 +477,7 @@ static void xfer_fd(int fd, char cmd)
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t execute_sockd(char *buf, size_t buflen)
|
static size_t execute_sockd(char buf[static 1], size_t buflen)
|
||||||
{
|
{
|
||||||
if (!buflen)
|
if (!buflen)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
extern uid_t sockd_uid;
|
extern uid_t sockd_uid;
|
||||||
extern gid_t sockd_gid;
|
extern gid_t sockd_gid;
|
||||||
int request_sockd_fd(char *buf, size_t buflen, char *response);
|
int request_sockd_fd(char buf[static 1], size_t buflen, char *response);
|
||||||
void sockd_main(void);
|
void sockd_main(void);
|
||||||
|
|
||||||
#endif /* NDHC_SOCKD_H_ */
|
#endif /* NDHC_SOCKD_H_ */
|
||||||
|
76
src/state.c
76
src/state.c
@ -41,26 +41,26 @@
|
|||||||
#include "ndhc.h"
|
#include "ndhc.h"
|
||||||
#include "sys.h"
|
#include "sys.h"
|
||||||
|
|
||||||
static void selecting_packet(struct client_state_t *cs, struct dhcpmsg *packet,
|
static void selecting_packet(struct client_state_t cs[static 1], struct dhcpmsg *packet,
|
||||||
uint8_t msgtype, uint32_t srcaddr);
|
uint8_t msgtype, uint32_t srcaddr);
|
||||||
static void an_packet(struct client_state_t *cs, struct dhcpmsg *packet,
|
static void an_packet(struct client_state_t cs[static 1], struct dhcpmsg *packet,
|
||||||
uint8_t msgtype, uint32_t srcaddr);
|
uint8_t msgtype, uint32_t srcaddr);
|
||||||
static void selecting_timeout(struct client_state_t *cs, long long nowts);
|
static void selecting_timeout(struct client_state_t cs[static 1], long long nowts);
|
||||||
static void requesting_timeout(struct client_state_t *cs, long long nowts);
|
static void requesting_timeout(struct client_state_t cs[static 1], long long nowts);
|
||||||
static void bound_timeout(struct client_state_t *cs, long long nowts);
|
static void bound_timeout(struct client_state_t cs[static 1], long long nowts);
|
||||||
static void renewing_timeout(struct client_state_t *cs, long long nowts);
|
static void renewing_timeout(struct client_state_t cs[static 1], long long nowts);
|
||||||
static void rebinding_timeout(struct client_state_t *cs, long long nowts);
|
static void rebinding_timeout(struct client_state_t cs[static 1], long long nowts);
|
||||||
static void released_timeout(struct client_state_t *cs, long long nowts);
|
static void released_timeout(struct client_state_t cs[static 1], long long nowts);
|
||||||
static void xmit_release(struct client_state_t *cs);
|
static void xmit_release(struct client_state_t cs[static 1]);
|
||||||
static void print_release(struct client_state_t *cs);
|
static void print_release(struct client_state_t cs[static 1]);
|
||||||
static void frenew(struct client_state_t *cs);
|
static void frenew(struct client_state_t cs[static 1]);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void (*packet_fn)(struct client_state_t *cs, struct dhcpmsg *packet,
|
void (*packet_fn)(struct client_state_t cs[static 1], struct dhcpmsg *packet,
|
||||||
uint8_t msgtype, uint32_t srcaddr);
|
uint8_t msgtype, uint32_t srcaddr);
|
||||||
void (*timeout_fn)(struct client_state_t *cs, long long nowts);
|
void (*timeout_fn)(struct client_state_t cs[static 1], long long nowts);
|
||||||
void (*force_renew_fn)(struct client_state_t *cs);
|
void (*force_renew_fn)(struct client_state_t cs[static 1]);
|
||||||
void (*force_release_fn)(struct client_state_t *cs);
|
void (*force_release_fn)(struct client_state_t cs[static 1]);
|
||||||
} dhcp_state_t;
|
} dhcp_state_t;
|
||||||
|
|
||||||
static const dhcp_state_t dhcp_states[] = {
|
static const dhcp_state_t dhcp_states[] = {
|
||||||
@ -78,7 +78,7 @@ static const dhcp_state_t dhcp_states[] = {
|
|||||||
static unsigned int num_dhcp_requests;
|
static unsigned int num_dhcp_requests;
|
||||||
static long long dhcp_wake_ts = -1;
|
static long long dhcp_wake_ts = -1;
|
||||||
|
|
||||||
static int delay_timeout(struct client_state_t *cs, size_t numpackets)
|
static int delay_timeout(struct client_state_t cs[static 1], size_t numpackets)
|
||||||
{
|
{
|
||||||
int to = 64;
|
int to = 64;
|
||||||
char tot[] = { 4, 8, 16, 32, 64 };
|
char tot[] = { 4, 8, 16, 32, 64 };
|
||||||
@ -88,7 +88,7 @@ static int delay_timeout(struct client_state_t *cs, size_t numpackets)
|
|||||||
return to * 1000 + (nk_random_u32(&cs->rnd32_state) & 0x7fffffffu) % 1000;
|
return to * 1000 + (nk_random_u32(&cs->rnd32_state) & 0x7fffffffu) % 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void reinit_shared_deconfig(struct client_state_t *cs)
|
static void reinit_shared_deconfig(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
ifchange_deconfig(cs);
|
ifchange_deconfig(cs);
|
||||||
arp_close_fd(cs);
|
arp_close_fd(cs);
|
||||||
@ -101,7 +101,7 @@ static void reinit_shared_deconfig(struct client_state_t *cs)
|
|||||||
arp_reset_send_stats();
|
arp_reset_send_stats();
|
||||||
}
|
}
|
||||||
|
|
||||||
void reinit_selecting(struct client_state_t *cs, int timeout)
|
void reinit_selecting(struct client_state_t cs[static 1], int timeout)
|
||||||
{
|
{
|
||||||
reinit_shared_deconfig(cs);
|
reinit_shared_deconfig(cs);
|
||||||
cs->dhcpState = DS_SELECTING;
|
cs->dhcpState = DS_SELECTING;
|
||||||
@ -109,7 +109,7 @@ void reinit_selecting(struct client_state_t *cs, int timeout)
|
|||||||
start_dhcp_listen(cs);
|
start_dhcp_listen(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_released(struct client_state_t *cs)
|
static void set_released(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
reinit_shared_deconfig(cs);
|
reinit_shared_deconfig(cs);
|
||||||
cs->dhcpState = DS_RELEASED;
|
cs->dhcpState = DS_RELEASED;
|
||||||
@ -121,7 +121,7 @@ static void set_released(struct client_state_t *cs)
|
|||||||
// been received within the response wait time. If we've not exceeded the
|
// been received within the response wait time. If we've not exceeded the
|
||||||
// maximum number of request retransmits, then send another packet and wait
|
// maximum number of request retransmits, then send another packet and wait
|
||||||
// again. Otherwise, return to the DHCP initialization state.
|
// again. Otherwise, return to the DHCP initialization state.
|
||||||
static void requesting_timeout(struct client_state_t *cs, long long nowts)
|
static void requesting_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
if (num_dhcp_requests < 5) {
|
if (num_dhcp_requests < 5) {
|
||||||
if (send_selecting(cs) < 0)
|
if (send_selecting(cs) < 0)
|
||||||
@ -135,7 +135,7 @@ static void requesting_timeout(struct client_state_t *cs, long long nowts)
|
|||||||
|
|
||||||
// Triggered when the lease has been held for a significant fraction of its
|
// Triggered when the lease has been held for a significant fraction of its
|
||||||
// total time, and it is time to renew the lease so that it is not lost.
|
// total time, and it is time to renew the lease so that it is not lost.
|
||||||
static void bound_timeout(struct client_state_t *cs, long long nowts)
|
static void bound_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
long long rnt = cs->leaseStartTime + cs->renewTime * 1000;
|
long long rnt = cs->leaseStartTime + cs->renewTime * 1000;
|
||||||
if (nowts < rnt) {
|
if (nowts < rnt) {
|
||||||
@ -153,7 +153,7 @@ static void bound_timeout(struct client_state_t *cs, long long nowts)
|
|||||||
// expires. Check to see if the lease is still valid, and if it is, send
|
// expires. Check to see if the lease is still valid, and if it is, send
|
||||||
// a unicast DHCP renew packet. If it is not, then change to the REBINDING
|
// a unicast DHCP renew packet. If it is not, then change to the REBINDING
|
||||||
// state to send broadcast queries.
|
// state to send broadcast queries.
|
||||||
static void renewing_timeout(struct client_state_t *cs, long long nowts)
|
static void renewing_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
long long rbt = cs->leaseStartTime + cs->rebindTime * 1000;
|
long long rbt = cs->leaseStartTime + cs->rebindTime * 1000;
|
||||||
if (nowts < rbt) {
|
if (nowts < rbt) {
|
||||||
@ -175,7 +175,7 @@ static void renewing_timeout(struct client_state_t *cs, long long nowts)
|
|||||||
// received within the response wait time. Check to see if the lease is still
|
// received within the response wait time. Check to see if the lease is still
|
||||||
// valid, and if it is, send a broadcast DHCP renew packet. If it is not, then
|
// valid, and if it is, send a broadcast DHCP renew packet. If it is not, then
|
||||||
// change to the SELECTING state to get a new lease.
|
// change to the SELECTING state to get a new lease.
|
||||||
static void rebinding_timeout(struct client_state_t *cs, long long nowts)
|
static void rebinding_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
long long elt = cs->leaseStartTime + cs->lease * 1000;
|
long long elt = cs->leaseStartTime + cs->lease * 1000;
|
||||||
if (nowts < elt) {
|
if (nowts < elt) {
|
||||||
@ -194,14 +194,14 @@ static void rebinding_timeout(struct client_state_t *cs, long long nowts)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void released_timeout(struct client_state_t *cs, long long nowts)
|
static void released_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
(void)cs;
|
(void)cs;
|
||||||
(void)nowts;
|
(void)nowts;
|
||||||
dhcp_wake_ts = -1;
|
dhcp_wake_ts = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int validate_serverid(struct client_state_t *cs, struct dhcpmsg *packet,
|
static int validate_serverid(struct client_state_t cs[static 1], struct dhcpmsg *packet,
|
||||||
char *typemsg)
|
char *typemsg)
|
||||||
{
|
{
|
||||||
int found;
|
int found;
|
||||||
@ -223,7 +223,7 @@ static int validate_serverid(struct client_state_t *cs, struct dhcpmsg *packet,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Can transition to DS_BOUND or DS_SELECTING.
|
// Can transition to DS_BOUND or DS_SELECTING.
|
||||||
static void an_packet(struct client_state_t *cs, struct dhcpmsg *packet,
|
static void an_packet(struct client_state_t cs[static 1], struct dhcpmsg *packet,
|
||||||
uint8_t msgtype, uint32_t srcaddr)
|
uint8_t msgtype, uint32_t srcaddr)
|
||||||
{
|
{
|
||||||
(void)srcaddr;
|
(void)srcaddr;
|
||||||
@ -280,7 +280,7 @@ static void an_packet(struct client_state_t *cs, struct dhcpmsg *packet,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void selecting_packet(struct client_state_t *cs, struct dhcpmsg *packet,
|
static void selecting_packet(struct client_state_t cs[static 1], struct dhcpmsg *packet,
|
||||||
uint8_t msgtype, uint32_t srcaddr)
|
uint8_t msgtype, uint32_t srcaddr)
|
||||||
{
|
{
|
||||||
if (msgtype == DHCPOFFER) {
|
if (msgtype == DHCPOFFER) {
|
||||||
@ -316,7 +316,7 @@ static void selecting_packet(struct client_state_t *cs, struct dhcpmsg *packet,
|
|||||||
// been received within the response wait time. If we've not exceeded the
|
// been received within the response wait time. If we've not exceeded the
|
||||||
// maximum number of discover retransmits, then send another packet and wait
|
// maximum number of discover retransmits, then send another packet and wait
|
||||||
// again. Otherwise, background or fail.
|
// again. Otherwise, background or fail.
|
||||||
static void selecting_timeout(struct client_state_t *cs, long long nowts)
|
static void selecting_timeout(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
if (cs->init && num_dhcp_requests >= 2) {
|
if (cs->init && num_dhcp_requests >= 2) {
|
||||||
if (client_config.background_if_no_lease) {
|
if (client_config.background_if_no_lease) {
|
||||||
@ -336,7 +336,7 @@ static void selecting_timeout(struct client_state_t *cs, long long nowts)
|
|||||||
num_dhcp_requests++;
|
num_dhcp_requests++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xmit_release(struct client_state_t *cs)
|
static void xmit_release(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
char clibuf[INET_ADDRSTRLEN];
|
char clibuf[INET_ADDRSTRLEN];
|
||||||
char svrbuf[INET_ADDRSTRLEN];
|
char svrbuf[INET_ADDRSTRLEN];
|
||||||
@ -352,13 +352,13 @@ static void xmit_release(struct client_state_t *cs)
|
|||||||
print_release(cs);
|
print_release(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_release(struct client_state_t *cs)
|
static void print_release(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
log_line("%s: ndhc going to sleep. Wake it by sending a SIGUSR1.", client_config.interface);
|
log_line("%s: ndhc going to sleep. Wake it by sending a SIGUSR1.", client_config.interface);
|
||||||
set_released(cs);
|
set_released(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void frenew(struct client_state_t *cs)
|
static void frenew(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (cs->dhcpState == DS_BOUND) {
|
if (cs->dhcpState == DS_BOUND) {
|
||||||
log_line("%s: Forcing a DHCP renew...", client_config.interface);
|
log_line("%s: Forcing a DHCP renew...", client_config.interface);
|
||||||
@ -371,7 +371,7 @@ static void frenew(struct client_state_t *cs)
|
|||||||
reinit_selecting(cs, 0);
|
reinit_selecting(cs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ifup_action(struct client_state_t *cs)
|
void ifup_action(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
// If we have a lease, check to see if our gateway is still valid via ARP.
|
// If we have a lease, check to see if our gateway is still valid via ARP.
|
||||||
// If it fails, state -> SELECTING.
|
// If it fails, state -> SELECTING.
|
||||||
@ -392,40 +392,40 @@ void ifup_action(struct client_state_t *cs)
|
|||||||
reinit_selecting(cs, 0);
|
reinit_selecting(cs, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ifdown_action(struct client_state_t *cs)
|
void ifdown_action(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
log_line("%s: Interface shut down. Going to sleep.",
|
log_line("%s: Interface shut down. Going to sleep.",
|
||||||
client_config.interface);
|
client_config.interface);
|
||||||
set_released(cs);
|
set_released(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ifnocarrier_action(struct client_state_t *cs)
|
void ifnocarrier_action(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
(void)cs;
|
(void)cs;
|
||||||
log_line("%s: Carrier down.", client_config.interface);
|
log_line("%s: Carrier down.", client_config.interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
void packet_action(struct client_state_t *cs, struct dhcpmsg *packet,
|
void packet_action(struct client_state_t cs[static 1], struct dhcpmsg *packet,
|
||||||
uint8_t msgtype, uint32_t srcaddr)
|
uint8_t msgtype, uint32_t srcaddr)
|
||||||
{
|
{
|
||||||
if (dhcp_states[cs->dhcpState].packet_fn)
|
if (dhcp_states[cs->dhcpState].packet_fn)
|
||||||
dhcp_states[cs->dhcpState].packet_fn(cs, packet, msgtype, srcaddr);
|
dhcp_states[cs->dhcpState].packet_fn(cs, packet, msgtype, srcaddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void timeout_action(struct client_state_t *cs, long long nowts)
|
void timeout_action(struct client_state_t cs[static 1], long long nowts)
|
||||||
{
|
{
|
||||||
handle_arp_timeout(cs, nowts);
|
handle_arp_timeout(cs, nowts);
|
||||||
if (dhcp_states[cs->dhcpState].timeout_fn)
|
if (dhcp_states[cs->dhcpState].timeout_fn)
|
||||||
dhcp_states[cs->dhcpState].timeout_fn(cs, nowts);
|
dhcp_states[cs->dhcpState].timeout_fn(cs, nowts);
|
||||||
}
|
}
|
||||||
|
|
||||||
void force_renew_action(struct client_state_t *cs)
|
void force_renew_action(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (dhcp_states[cs->dhcpState].force_renew_fn)
|
if (dhcp_states[cs->dhcpState].force_renew_fn)
|
||||||
dhcp_states[cs->dhcpState].force_renew_fn(cs);
|
dhcp_states[cs->dhcpState].force_renew_fn(cs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void force_release_action(struct client_state_t *cs)
|
void force_release_action(struct client_state_t cs[static 1])
|
||||||
{
|
{
|
||||||
if (dhcp_states[cs->dhcpState].force_release_fn)
|
if (dhcp_states[cs->dhcpState].force_release_fn)
|
||||||
dhcp_states[cs->dhcpState].force_release_fn(cs);
|
dhcp_states[cs->dhcpState].force_release_fn(cs);
|
||||||
|
16
src/state.h
16
src/state.h
@ -43,17 +43,17 @@ typedef enum {
|
|||||||
DS_NUM_STATES,
|
DS_NUM_STATES,
|
||||||
} dhcp_states_t;
|
} dhcp_states_t;
|
||||||
|
|
||||||
void reinit_selecting(struct client_state_t *cs, int timeout);
|
void reinit_selecting(struct client_state_t cs[static 1], int timeout);
|
||||||
|
|
||||||
void packet_action(struct client_state_t *cs, struct dhcpmsg *packet,
|
void packet_action(struct client_state_t cs[static 1], struct dhcpmsg *packet,
|
||||||
uint8_t msgtype, uint32_t srcaddr);
|
uint8_t msgtype, uint32_t srcaddr);
|
||||||
void timeout_action(struct client_state_t *cs, long long nowts);
|
void timeout_action(struct client_state_t cs[static 1], long long nowts);
|
||||||
void force_renew_action(struct client_state_t *cs);
|
void force_renew_action(struct client_state_t cs[static 1]);
|
||||||
void force_release_action(struct client_state_t *cs);
|
void force_release_action(struct client_state_t cs[static 1]);
|
||||||
|
|
||||||
void ifup_action(struct client_state_t *cs);
|
void ifup_action(struct client_state_t cs[static 1]);
|
||||||
void ifnocarrier_action(struct client_state_t *cs);
|
void ifnocarrier_action(struct client_state_t cs[static 1]);
|
||||||
void ifdown_action(struct client_state_t *cs);
|
void ifdown_action(struct client_state_t cs[static 1]);
|
||||||
long long dhcp_get_wake_ts(void);
|
long long dhcp_get_wake_ts(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user