Improve the process for GNU tools
[minix3.git] / minix / commands / dhcpd / dhcpd.h
blob35d729d3e4535ee0175e568aaef9fe34d2dd7f36
1 /* dhcpd.h - Dynamic Host Configuration Protocol daemon.
2 * Author: Kees J. Bot
3 * 16 Dec 2000
4 */
6 #define nil ((void*)0)
8 #include <minix/paths.h>
9 #include <net/if_ether.h>
11 /* Paths to files. */
12 #define PATH_DHCPCONF _PATH_DHCPCONF
13 #define PATH_DHCPPID _PATH_DHCPPID
14 #define PATH_DHCPCACHE _PATH_DHCPCACHE
15 #define PATH_DHCPPOOL _PATH_DHCPPOOL
17 #define CLID_MAX 32 /* Maximum client ID length. */
19 #ifndef EXTERN
20 #define EXTERN extern
21 #endif
23 extern int lwip;
25 EXTERN char *program; /* This program's name. */
26 extern char *configfile; /* Configuration file. */
27 extern char *poolfile; /* Dynamic address pool. */
28 EXTERN int serving; /* True if being a DHCP server. */
29 EXTERN unsigned test; /* Test level. */
30 EXTERN unsigned debug; /* Debug level. */
31 EXTERN asynchio_t asyn; /* Bookkeeping for all async I/O. */
33 /* BOOTP UDP ports: (That they are different is quite stupid.) */
34 EXTERN u16_t port_server; /* Port server listens on. */
35 EXTERN u16_t port_client; /* Port client listens on. */
37 #define arraysize(a) (sizeof(a) / sizeof((a)[0]))
38 #define arraylimit(a) ((a) + arraysize(a))
39 #define between(a,c,z) (sizeof(c) <= sizeof(unsigned) ? \
40 (unsigned) (c) - (a) <= (unsigned) (z) - (a) : \
41 (unsigned long) (c) - (a) <= (unsigned long) (z) - (a))
43 /* To treat objects as octet arrays: */
44 #define B(a) ((u8_t *) (a))
46 /* Times. */
47 EXTERN time_t start, now; /* Start and current time. */
48 EXTERN time_t event; /* Time of the next timed event. */
50 /* Special times and periods: */
51 #define NEVER (sizeof(time_t) <= sizeof(int) ? INT_MAX : LONG_MAX)
52 #define DELTA_FIRST 4 /* Between first and second query. */
53 #define DELTA_FAST 64 /* Unbound queries this often. */
54 #define DELTA_SLOW 512 /* Bound queries are more relaxed. */
55 #define N_SOLICITS 3 /* Number of solicitations. */
56 #define DELTA_SOL 3 /* Time between solicitations. */
57 #define DELTA_ADV 2048 /* Router adverts to self lifetime. */
59 /* Buffers for packets. */
60 typedef struct buf {
61 eth_hdr_t *eth; /* Ethernet header in payload. */
62 ip_hdr_t *ip; /* IP header in payload. */
63 udp_hdr_t *udp; /* UDP header in payload. */
64 udp_io_hdr_t *udpio; /* UDP I/O header in payload. */
65 dhcp_t *dhcp; /* DHCP data in payload. */
66 u8_t pad[2]; /* buf[] must start at 2 mod 4. */
67 /* Payload: */
68 u8_t buf[ETH_MAX_PACK_SIZE];
69 } buf_t;
71 #define BUF_ETH_SIZE (ETH_MAX_PACK_SIZE)
72 #define BUF_IP_SIZE (BUF_ETH_SIZE - sizeof(eth_hdr_t))
73 #define BUF_UDP_SIZE (BUF_IP_SIZE - sizeof(ip_hdr_t) - sizeof(udp_hdr_t) \
74 + sizeof(udp_io_hdr_t))
76 /* Type of network device open: Ethernet, ICMP, BOOTP client, BOOTP server. */
77 typedef enum { FT_CLOSED, FT_ETHERNET, FT_ICMP, FT_BOOTPC, FT_BOOTPS } fdtype_t;
79 #define FT_ALL FT_CLOSED /* To close all open descriptors at once. */
81 typedef struct fd { /* An open descriptor. */
82 i8_t fd; /* Open descriptor. */
83 u8_t fdtype; /* Type of network open. */
84 char device[sizeof("/dev/eth###")]; /* Device name. */
85 u8_t n; /* Network that owns it. */
86 buf_t *bp; /* Associated packet buffer. */
87 time_t since; /* Open since when? */
88 } fd_t;
90 /* Network state: Any IP device, Ethernet in sink mode, True Ethernet. */
91 typedef enum { NT_IP, NT_SINK, NT_ETHERNET } nettype_t;
93 typedef struct network { /* Information on a network. */
94 u8_t n; /* Network number. */
95 ether_addr_t eth; /* Ethernet address of this net. */
96 u8_t type; /* What kind of net is this? */
97 i8_t sol_ct; /* Router solicitation count. */
98 ether_addr_t conflict; /* Address conflict with this one. */
99 unsigned flags; /* Various flags. */
100 fd_t *fdp; /* Current open device. */
101 struct network *wait; /* Wait for a resource list. */
102 ipaddr_t ip; /* IP address of this net. */
103 ipaddr_t mask; /* Associated netmask. */
104 ipaddr_t gateway; /* My router. */
105 ipaddr_t server; /* My DHCP server. */
106 const char *hostname; /* Optional hostname to query for. */
107 time_t start; /* Query or lease start time. */
108 time_t delta; /* Query again after delta seconds. */
109 time_t renew; /* Next query or go into renewal. */
110 time_t rebind; /* When to go into rebind. */
111 time_t lease; /* When our lease expires. */
112 time_t solicit; /* Time to do a router solicitation. */
113 } network_t;
115 /* Flags. */
116 #define NF_NEGOTIATING 0x001 /* Negotiating with a DHCP server. */
117 #define NF_BOUND 0x002 /* Address configured through DHCP. */
118 #define NF_SERVING 0x004 /* I'm a server on this network. */
119 #define NF_RELAYING 0x008 /* I'm relaying for this network. */
120 #define NF_WAIT 0x010 /* Wait for a resource to free up. */
121 #define NF_IRDP 0x020 /* IRDP is used on this net. */
122 #define NF_CONFLICT 0x040 /* There is an address conflict. */
123 #define NF_POSSESSIVE 0x080 /* Keep address if lease expires. */
124 #define NF_INFORM 0x100 /* It's ok to answer DHCPINFORM. */
126 /* Functions defined in dhcpd.c. */
127 void report(const char *label);
128 void fatal(const char *label);
129 void *allocate(size_t size);
130 int ifname2if(const char *name);
131 network_t *if2net(int n);
133 /* Devices.c */
134 void get_buf(buf_t **bp);
135 void put_buf(buf_t **bp);
136 void give_buf(buf_t **dbp, buf_t **sbp);
137 network_t *newnetwork(void);
138 void closefd(fd_t *fdp);
139 int opendev(network_t *np, fdtype_t fdtype, int compete);
140 void closedev(network_t *np, fdtype_t fdtype);
141 char *ipdev(int n);
142 void set_ipconf(char *device, ipaddr_t ip, ipaddr_t mask, unsigned mtu);
144 /* Ether.c */
145 void udp2ether(buf_t *bp, network_t *np);
146 int ether2udp(buf_t *bp);
147 void make_arp(buf_t *bp, network_t *np);
148 int is_arp_me(buf_t *bp, network_t *np);
149 void icmp_solicit(buf_t *bp);
150 void icmp_advert(buf_t *bp, network_t *np);
151 ipaddr_t icmp_is_advert(buf_t *bp);
153 /* Tags.c */
154 #define gettag(dp, st, pd, pl) dhcp_gettag((dp), (st), (pd), (pl))
155 void settag(dhcp_t *dp, int tag, void *data, size_t len);
156 char *cidr_ntoa(ipaddr_t addr, ipaddr_t mask);
157 void ether2clid(u8_t *clid, ether_addr_t *eth);
158 void initdhcpconf(void);
159 int makedhcp(dhcp_t *dp, u8_t *class, size_t calen, u8_t *client, size_t cilen,
160 ipaddr_t ip, ipaddr_t ifip, network_t *np);
161 char *dhcptypename(int type);
162 void printdhcp(dhcp_t *dp);