source: trunk/minix/commands/dhcpd/dhcpd.h@ 15

Last change on this file since 15 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

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