declarations.
-/* $OpenBSD: bpf.c,v 1.58 2017/07/09 19:19:58 krw Exp $ */
+/* $OpenBSD: bpf.c,v 1.59 2017/07/10 00:47:47 krw Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
void
if_register_bpf(struct interface_info *ifi)
{
- struct ifreq ifr;
- int sock;
+ struct ifreq ifr;
+ int sock;
if ((sock = open("/dev/bpf", O_RDWR | O_CLOEXEC)) == -1)
fatal("Can't open bpf");
void
if_register_send(struct interface_info *ifi)
{
- int sock, on = 1;
+ int sock, on = 1;
/*
* Use raw socket for unicast send.
void
if_register_receive(struct interface_info *ifi)
{
- struct bpf_version v;
- struct bpf_program p;
- int flag = 1, sz;
+ struct bpf_version v;
+ struct bpf_program p;
+ int flag = 1, sz;
/* Open a BPF device and hang it on this interface. */
if_register_bpf(ifi);
ssize_t
send_packet(struct interface_info *ifi, struct in_addr from, struct in_addr to)
{
- struct sockaddr_in dest;
- struct ether_header eh;
- struct ip ip;
- struct udphdr udp;
- struct iovec iov[4];
- struct msghdr msg;
- struct dhcp_packet *packet = &ifi->sent_packet;
- ssize_t result;
- int iovcnt = 0, len = ifi->sent_packet_length;
+ struct iovec iov[4];
+ struct sockaddr_in dest;
+ struct ether_header eh;
+ struct ip ip;
+ struct udphdr udp;
+ struct msghdr msg;
+ struct dhcp_packet *packet = &ifi->sent_packet;
+ ssize_t result;
+ int iovcnt = 0, len = ifi->sent_packet_length;
memset(&dest, 0, sizeof(dest));
dest.sin_family = AF_INET;
receive_packet(struct interface_info *ifi, struct sockaddr_in *from,
struct ether_addr *hfrom)
{
- struct dhcp_packet *packet = &ifi->recv_packet;
- int length = 0, offset = 0;
- struct bpf_hdr hdr;
+ struct bpf_hdr hdr;
+ struct dhcp_packet *packet = &ifi->recv_packet;
+ int length = 0, offset = 0;
/*
* All this complexity is because BPF doesn't guarantee that
-/* $OpenBSD: clparse.c,v 1.121 2017/07/09 21:29:19 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.122 2017/07/10 00:47:47 krw Exp $ */
/* Parser for dhclient config and lease files. */
parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
char *name)
{
- char *val;
- unsigned int len;
- int token;
+ char *val;
+ unsigned int len;
+ int token;
token = next_token(&val, cfile);
void
parse_reject_statement(FILE *cfile)
{
- struct reject_elem *elem;
- struct in_addr addr;
- int token;
+ struct in_addr addr;
+ struct reject_elem *elem;
+ int token;
do {
if (!parse_ip_addr(cfile, &addr))
-/* $OpenBSD: conflex.c,v 1.41 2017/07/09 19:19:58 krw Exp $ */
+/* $OpenBSD: conflex.c,v 1.42 2017/07/10 00:47:47 krw Exp $ */
/* Lexical scanner for dhclient config file. */
static int
get_token(FILE *cfile)
{
- int c, ttok;
static char tb[2];
+ int c, ttok;
int l, p, u;
u = ugflag;
int
peek_token(char **rval, FILE *cfile)
{
- int x;
+ int x;
if (!token) {
tlpos = lexchar;
static void
skip_to_eol(FILE *cfile)
{
- int c;
+ int c;
do {
c = get_char(cfile);
static int
read_string(FILE *cfile)
{
- int i, c, bs;
+ int i, c, bs;
/*
* Read in characters until an un-escaped '"' is encountered.
static int
read_num_or_name(int c, FILE *cfile)
{
- unsigned int i, xdigits;
- int rv;
+ unsigned int i, xdigits;
+ int rv;
xdigits = isxdigit(c) ? 1 : 0;
static const struct keywords {
const char *k_name;
- int k_val;
+ int k_val;
} keywords[] = {
{ "append", TOK_APPEND },
{ "backoff-cutoff", TOK_BACKOFF_CUTOFF },
static int
intern(char *atom, int dfv)
{
- const struct keywords *p;
+ const struct keywords *p;
p = bsearch(atom, keywords, sizeof(keywords)/sizeof(keywords[0]),
sizeof(keywords[0]), kw_cmp);
-/* $OpenBSD: dhclient.c,v 1.463 2017/07/09 19:19:58 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.464 2017/07/10 00:47:47 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
int
findproto(char *cp, int n)
{
- struct sockaddr *sa;
- unsigned int i;
+ struct sockaddr *sa;
+ unsigned int i;
if (n == 0)
return -1;
struct sockaddr *
get_ifa(char *cp, int n)
{
- struct sockaddr *sa;
- unsigned int i;
+ struct sockaddr *sa;
+ unsigned int i;
if (n == 0)
return NULL;
void
state_preboot(struct interface_info *ifi)
{
- static int preamble;
- time_t cur_time;
- int interval;
+ static int preamble;
+ time_t cur_time;
+ int interval;
time(&cur_time);
void
state_selecting(struct interface_info *ifi)
{
- struct option_data *option;
+ struct option_data *option;
cancel_timeout(ifi);
void
dhcpoffer(struct interface_info *ifi, struct option_data *options, char *info)
{
- struct client_lease *lease;
- time_t stop_selecting;
+ struct client_lease *lease;
+ time_t stop_selecting;
if (ifi->state != S_SELECTING) {
#ifdef DEBUG
void
dhcpack(struct interface_info *ifi, struct option_data *options, char *info)
{
- struct client_lease *lease;
+ struct client_lease *lease;
if (ifi->state != S_REBOOTING &&
ifi->state != S_REQUESTING &&
void
bind_lease(struct interface_info *ifi)
{
- struct in_addr gateway, mask;
- struct option_data *opt;
- struct option_data *options;
- struct client_lease *lease, *pl;
- time_t cur_time;
- int seen;
+ struct in_addr gateway, mask;
+ struct option_data *opt;
+ struct option_data *options;
+ struct client_lease *lease, *pl;
+ time_t cur_time;
+ int seen;
/*
* Clear out any old resolv_conf in case the lease has been here
void
state_bound(struct interface_info *ifi)
{
- struct option_data *opt;
- struct in_addr *dest;
+ struct option_data *opt;
+ struct in_addr *dest;
ifi->xid = arc4random();
make_request(ifi, ifi->active);
int
addressinuse(char *name, struct in_addr address, char *ifname)
{
- struct ifaddrs *ifap, *ifa;
- struct sockaddr_in *sin;
- int used = 0;
+ struct ifaddrs *ifap, *ifa;
+ struct sockaddr_in *sin;
+ int used = 0;
if (getifaddrs(&ifap) != 0) {
log_warn("addressinuse: getifaddrs");
struct client_lease *
packet_to_lease(struct interface_info *ifi, struct option_data *options)
{
- struct dhcp_packet *packet = &ifi->recv_packet;
- char ifname[IF_NAMESIZE];
- struct client_lease *lease;
- char *pretty, *buf, *name;
- int i;
+ char ifname[IF_NAMESIZE];
+ struct dhcp_packet *packet = &ifi->recv_packet;
+ struct client_lease *lease;
+ char *pretty, *buf, *name;
+ int i;
lease = calloc(1, sizeof(struct client_lease));
if (lease == NULL) {
void
send_discover(struct interface_info *ifi)
{
- struct dhcp_packet *packet = &ifi->sent_packet;
- time_t cur_time;
- ssize_t rslt;
- int interval;
+ struct dhcp_packet *packet = &ifi->sent_packet;
+ time_t cur_time;
+ ssize_t rslt;
+ int interval;
time(&cur_time);
void
send_request(struct interface_info *ifi)
{
- struct dhcp_packet *packet = &ifi->sent_packet;
- struct sockaddr_in destination;
- struct in_addr from;
- time_t cur_time;
- int interval;
+ struct sockaddr_in destination;
+ struct in_addr from;
+ struct dhcp_packet *packet = &ifi->sent_packet;
+ time_t cur_time;
+ int interval;
time(&cur_time);
void
free_client_lease(struct client_lease *lease)
{
- int i;
+ int i;
/* Static leases are forever. */
if (lease == NULL || lease->is_static)
void
rewrite_client_leases(struct interface_info *ifi)
{
- struct client_lease *lp;
- char *leasestr;
- time_t cur_time;
+ struct client_lease *lp;
+ char *leasestr;
+ time_t cur_time;
if (!leaseFile) /* XXX */
fatalx("lease file not open");
rewrite_option_db(char *name, struct client_lease *offered,
struct client_lease *effective)
{
- char *leasestr;
+ char *leasestr;
if (!optionDB)
return;
char *
lease_as_string(char *ifname, char *type, struct client_lease *lease)
{
- static char string[8192];
- char timebuf[27]; /* to hold "6 2017/04/08 05:47:50 UTC;" */
- struct option_data *opt;
- char *buf, *name;
- size_t rslt;
- int i;
+ static char string[8192];
+ char timebuf[27]; /* 6 2017/04/08 05:47:50 UTC; */
+ struct option_data *opt;
+ char *buf, *name;
+ size_t rslt;
+ int i;
memset(string, 0, sizeof(string));
void
go_daemon(void)
{
- static int state = 0;
+ static int state = 0;
if (!daemonize || state)
return;
int
res_hnok(const char *name)
{
- const char *dn = name;
- int pch = '.', ch = (unsigned char)*dn++;
- int warn = 0;
+ const char *dn = name;
+ int pch = '.', ch = (unsigned char)*dn++;
+ int warn = 0;
while (ch != '\0') {
int nch = (unsigned char)*dn++;
int
res_hnok_list(const char *names)
{
- char *dupnames, *hn, *inputstring;
- int count;
+ char *dupnames, *hn, *inputstring;
+ int count;
if (strlen(names) >= DHCP_DOMAIN_SEARCH_LEN)
return 0;
void
get_ifname(struct interface_info *ifi, char *arg)
{
- struct ifgroupreq ifgr;
- struct ifg_req *ifg;
- unsigned int len;
- int s;
+ struct ifgroupreq ifgr;
+ struct ifg_req *ifg;
+ unsigned int len;
+ int s;
if (strcmp(arg, "egress") == 0) {
s = socket(AF_INET, SOCK_DGRAM, 0);
struct client_lease *
apply_defaults(struct client_lease *lease)
{
- struct client_lease *newlease;
- int i, j;
+ struct client_lease *newlease;
+ int i, j;
newlease = clone_lease(lease);
if (newlease == NULL)
struct client_lease *
clone_lease(struct client_lease *oldlease)
{
- struct client_lease *newlease;
- int i;
+ struct client_lease *newlease;
+ int i;
newlease = calloc(1, sizeof(struct client_lease));
if (newlease == NULL)
void
apply_ignore_list(char *ignore_list)
{
- uint8_t list[DHO_COUNT];
- char *p;
- int ix, i, j;
+ uint8_t list[DHO_COUNT];
+ char *p;
+ int ix, i, j;
memset(list, 0, sizeof(list));
ix = 0;
int
compare_lease(struct client_lease *active, struct client_lease *new)
{
- int i;
+ int i;
if (active == new)
return 0;
void
set_default_client_identifier(struct interface_info *ifi)
{
- struct option_data *opt;
+ struct option_data *opt;
/*
*
-/* $OpenBSD: kroute.c,v 1.105 2017/07/09 19:19:58 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.106 2017/07/10 00:47:47 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
void
flush_routes(void)
{
- int rslt;
+ int rslt;
rslt = imsg_compose(unpriv_ibuf, IMSG_FLUSH_ROUTES, 0, 0, -1, NULL, 0);
if (rslt == -1)
void
delete_route(int s, struct rt_msghdr *rtm)
{
- static int seqno;
- ssize_t rlen;
+ static int seqno;
+ ssize_t rlen;
rtm->rtm_type = RTM_DELETE;
rtm->rtm_seq = seqno++;
add_direct_route(struct in_addr dest, struct in_addr mask,
struct in_addr iface)
{
- struct in_addr ifa = { INADDR_ANY };
+ struct in_addr ifa = { INADDR_ANY };
add_route(dest, mask, iface, ifa,
RTA_DST | RTA_NETMASK | RTA_GATEWAY, RTF_CLONING | RTF_STATIC);
void
add_default_route(struct in_addr addr, struct in_addr gateway)
{
- struct in_addr netmask, dest;
- int addrs, flags;
+ struct in_addr netmask, dest;
+ int addrs, flags;
memset(&netmask, 0, sizeof(netmask));
memset(&dest, 0, sizeof(dest));
netmask.s_addr = INADDR_ANY; /* Not used for CLASSFULL! */
for (i = 0; (i + 2*sizeof(*addr)) <= static_routes->len;
- i += 2*sizeof(*addr)) {
+ i += 2*sizeof(*addr)) {
addr = (struct in_addr *)&static_routes->data[i];
if (addr->s_addr == INADDR_ANY)
continue; /* RFC 2132 says 0.0.0.0 is not allowed. */
int
create_route_label(struct sockaddr_rtlabel *label)
{
- int len;
+ int len;
memset(label, 0, sizeof(*label));
void
priv_add_route(int rdomain, struct imsg_add_route *imsg)
{
- char destbuf[INET_ADDRSTRLEN], gatewaybuf[INET_ADDRSTRLEN];
- char maskbuf[INET_ADDRSTRLEN], ifabuf[INET_ADDRSTRLEN];
- struct rt_msghdr rtm;
- struct sockaddr_in dest, gateway, mask, ifa;
- struct sockaddr_rtlabel label;
- struct iovec iov[6];
- int s, i, iovcnt = 0;
+ char destbuf[INET_ADDRSTRLEN];
+ char gatewaybuf[INET_ADDRSTRLEN];
+ char maskbuf[INET_ADDRSTRLEN];
+ char ifabuf[INET_ADDRSTRLEN];
+ struct iovec iov[6];
+ struct rt_msghdr rtm;
+ struct sockaddr_in dest, gateway, mask, ifa;
+ struct sockaddr_rtlabel label;
+ int s, i, iovcnt = 0;
if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1)
fatal("Routing Socket open failed");
void
delete_addresses(char *name)
{
- struct in_addr addr;
- struct ifaddrs *ifap, *ifa;
+ struct in_addr addr;
+ struct ifaddrs *ifap, *ifa;
if (getifaddrs(&ifap) != 0)
fatal("delete_addresses getifaddrs");
void
set_interface_mtu(int mtu)
{
- struct imsg_set_interface_mtu imsg;
- int rslt;
+ struct imsg_set_interface_mtu imsg;
+ int rslt;
imsg.mtu = mtu;
priv_set_interface_mtu(char *name, int ioctlfd,
struct imsg_set_interface_mtu *imsg)
{
- struct ifreq ifr;
+ struct ifreq ifr;
memset(&ifr, 0, sizeof(ifr));
void
add_address(struct in_addr addr, struct in_addr mask)
{
- struct imsg_add_address imsg;
- int rslt;
+ struct imsg_add_address imsg;
+ int rslt;
/* Note the address we are adding for RTM_NEWADDR filtering! */
adding = addr;
void
write_resolv_conf(uint8_t *contents, size_t sz)
{
- int rslt;
+ int rslt;
rslt = imsg_compose(unpriv_ibuf, IMSG_WRITE_RESOLV_CONF,
0, 0, -1, contents, sz);
int
resolv_conf_priority(int rdomain, int routefd)
{
- struct iovec iov[3];
+ struct iovec iov[3];
+ struct sockaddr_in sin;
struct {
struct rt_msghdr m_rtm;
char m_space[512];
- } m_rtmsg;
- struct sockaddr *rti_info[RTAX_MAX];
- struct sockaddr_in sin;
+ } m_rtmsg;
+ struct sockaddr *rti_info[RTAX_MAX];
struct sockaddr_rtlabel *sa_rl;
- pid_t pid;
- ssize_t len;
- int seq, rslt, iovcnt = 0;
+ pid_t pid;
+ ssize_t len;
+ int seq, rslt, iovcnt = 0;
rslt = 0;
struct option_data *domainname, struct option_data *nameservers,
struct option_data *domainsearch)
{
- char *dn, *ns, *nss[MAXNS], *contents, *courtesy, *p, *buf;
- size_t len;
- int i, rslt;
+ char *dn, *ns, *nss[MAXNS], *contents, *courtesy, *p, *buf;
+ size_t len;
+ int i, rslt;
memset(nss, 0, sizeof(nss));
void
populate_rti_info(struct sockaddr **rti_info, struct rt_msghdr *rtm)
{
- struct sockaddr *sa;
- int i;
+ struct sockaddr *sa;
+ int i;
sa = (struct sockaddr *)((char *)(rtm) + rtm->rtm_hdrlen);
-/* $OpenBSD: options.c,v 1.98 2017/07/09 19:19:58 krw Exp $ */
+/* $OpenBSD: options.c,v 1.99 2017/07/10 00:47:47 krw Exp $ */
/* DHCP options parsing and reassembly. */
int
pack_options(unsigned char *buf, int buflen, struct option_data *options)
{
- int ix, incr, length, bufix, code, lastopt = -1;
+ int ix, incr, length, bufix, code, lastopt = -1;
memset(buf, 0, buflen);
char *
pretty_print_string(unsigned char *src, size_t srclen, int emit_punct)
{
- static char string[8196];
- char visbuf[5];
- unsigned char *origsrc = src;
- size_t rslt = 0;
+ static char string[8196];
+ char visbuf[5];
+ unsigned char *origsrc = src;
+ size_t rslt = 0;
memset(string, 0, sizeof(string));
char *
pretty_print_classless_routes(unsigned char *src, size_t srclen)
{
- static char string[8196];
- char bitsbuf[5]; /* to hold "/nn " */
- struct in_addr net, gateway;
- unsigned int bytes;
- int bits, rslt;
+ static char string[8196];
+ char bitsbuf[5]; /* to hold "/nn " */
+ struct in_addr net, gateway;
+ unsigned int bytes;
+ int bits, rslt;
memset(string, 0, sizeof(string));
expand_search_domain_name(unsigned char *src, size_t srclen, int *offset,
unsigned char *domain_search)
{
- unsigned int i;
- int domain_name_len, label_len, pointer, pointed_len;
- char *cursor;
+ char *cursor;
+ unsigned int i;
+ int domain_name_len, label_len, pointer, pointed_len;
cursor = domain_search + strlen(domain_search);
domain_name_len = 0;
char *
pretty_print_domain_search(unsigned char *src, size_t srclen)
{
- static char domain_search[DHCP_DOMAIN_SEARCH_LEN];
- unsigned int offset;
- int len, expanded_len, domains;
- unsigned char *cursor;
+ static char domain_search[DHCP_DOMAIN_SEARCH_LEN];
+ unsigned char *cursor;
+ unsigned int offset;
+ int len, expanded_len, domains;
memset(domain_search, 0, sizeof(domain_search));
struct option_data *
unpack_options(struct dhcp_packet *packet)
{
- static struct option_data options[DHO_COUNT];
- int i;
+ static struct option_data options[DHO_COUNT];
+ int i;
for (i = 0; i < DHO_COUNT; i++) {
free(options[i].data);
-/* $OpenBSD: packet.c,v 1.38 2017/07/09 19:19:58 krw Exp $ */
+/* $OpenBSD: packet.c,v 1.39 2017/07/10 00:47:47 krw Exp $ */
/* Packet assembly code, originally contributed by Archie Cobbs. */
uint32_t
checksum(unsigned char *buf, uint32_t nbytes, uint32_t sum)
{
- unsigned int i;
+ unsigned int i;
/* Checksum all the pairs of bytes first. */
for (i = 0; i < (nbytes & ~1U); i += 2) {
ssize_t
decode_hw_header(unsigned char *buf, uint32_t buflen, struct ether_addr *from)
{
- struct ether_header eh;
+ struct ether_header eh;
if (buflen < sizeof(eh))
return -1;
-/* $OpenBSD: parse.c,v 1.57 2017/07/09 19:19:58 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.58 2017/07/10 00:47:47 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
char *
parse_string(FILE *cfile, unsigned int *len)
{
- static char unvisbuf[1500];
- char *val, *s;
- int i, token;
+ static char unvisbuf[1500];
+ char *val, *s;
+ int i, token;
token = next_token(&val, cfile);
if (token != TOK_STRING) {
int
parse_cidr(FILE *cfile, unsigned char *cidr)
{
- struct in_addr addr;
- int token;
- int len;
+ struct in_addr addr;
+ int token;
+ int len;
token = '.';
len = 0;
int
parse_ip_addr(FILE *cfile, struct in_addr *addr)
{
- struct in_addr buf;
- int len, token;
+ struct in_addr buf;
+ int len, token;
token = '.';
len = 0;
void
parse_lease_time(FILE *cfile, time_t *timep)
{
- uint32_t value;
+ uint32_t value;
if (!parse_decimal(cfile, (char *)&value, 'L')) {
parse_warn("expecting unsigned 32-bit decimal value.");
int
parse_decimal(FILE *cfile, unsigned char *buf, char fmt)
{
- char *val;
- const char *errstr;
- int bytes, token;
- long long numval, low, high;
+ const char *errstr;
+ char *val;
+ int bytes, token;
+ long long numval, low, high;
token = next_token(&val, cfile);
int
parse_hex(FILE *cfile, unsigned char *buf)
{
- char *val, *ep;
- int token;
- unsigned long ulval;
+ char *val, *ep;
+ unsigned long ulval;
+ int token;
token = next_token(&val, cfile);
time_t
parse_date(FILE *cfile)
{
- struct tm tm;
char timestr[26]; /* "w yyyy/mm/dd hh:mm:ss UTC" */
- char *val, *p;
- size_t n;
- time_t guess;
- int token;
+ struct tm tm;
+ char *val, *p;
+ size_t n;
+ time_t guess;
+ int token;
memset(timestr, 0, sizeof(timestr));
void
parse_warn(char *msg)
{
- static char spaces[81];
- unsigned int i;
+ static char spaces[81];
+ unsigned int i;
log_warnx("%s line %d: %s", tlname, lexline, msg);
log_warnx("%s", token_line);