dhcpd.h

Go to the documentation of this file.
00001 /*      dhcpd.h - Dynamic Host Configuration Protocol daemon.
00002  *                                                      Author: Kees J. Bot
00003  *                                                              16 Dec 2000
00004  */
00005 
00006 #define nil ((void*)0)
00007 
00008 #include <minix/paths.h>
00009 
00010 /* Paths to files. */
00011 #define PATH_DHCPCONF   _PATH_DHCPCONF
00012 #define PATH_DHCPPID    _PATH_DHCPPID
00013 #define PATH_DHCPCACHE  _PATH_DHCPCACHE
00014 #define PATH_DHCPPOOL   _PATH_DHCPPOOL
00015 
00016 #define CLID_MAX        32      /* Maximum client ID length. */
00017 
00018 #ifndef EXTERN
00019 #define EXTERN  extern
00020 #endif
00021 
00022 EXTERN char *program;           /* This program's name. */
00023 extern char *configfile;        /* Configuration file. */
00024 extern char *poolfile;          /* Dynamic address pool. */
00025 EXTERN int serving;             /* True if being a DHCP server. */
00026 EXTERN unsigned test;           /* Test level. */
00027 EXTERN unsigned debug;          /* Debug level. */
00028 EXTERN asynchio_t asyn;         /* Bookkeeping for all async I/O. */
00029 
00030 /* BOOTP UDP ports:  (That they are different is quite stupid.) */
00031 EXTERN u16_t port_server;       /* Port server listens on. */
00032 EXTERN u16_t port_client;       /* Port client listens on. */
00033 
00034 #define arraysize(a)    (sizeof(a) / sizeof((a)[0]))
00035 #define arraylimit(a)   ((a) + arraysize(a))
00036 #define between(a,c,z)  (sizeof(c) <= sizeof(unsigned) ? \
00037         (unsigned) (c) - (a) <= (unsigned) (z) - (a) : \
00038         (unsigned long) (c) - (a) <= (unsigned long) (z) - (a))
00039 
00040 /* To treat objects as octet arrays: */
00041 #define B(a)            ((u8_t *) (a))
00042 
00043 /* Times. */
00044 EXTERN time_t start, now;               /* Start and current time. */
00045 EXTERN time_t event;                    /* Time of the next timed event. */
00046 
00047 /* Special times and periods: */
00048 #define NEVER   (sizeof(time_t) <= sizeof(int) ? INT_MAX : LONG_MAX)
00049 #define DELTA_FIRST                4    /* Between first and second query. */
00050 #define DELTA_FAST                64    /* Unbound queries this often. */
00051 #define DELTA_SLOW               512    /* Bound queries are more relaxed. */
00052 #define N_SOLICITS                 3    /* Number of solicitations. */
00053 #define DELTA_SOL                  3    /* Time between solicitations. */
00054 #define DELTA_ADV               2048    /* Router adverts to self lifetime. */
00055 
00056 /* Buffers for packets. */
00057 typedef struct buf {
00058         eth_hdr_t       *eth;           /* Ethernet header in payload. */
00059         ip_hdr_t        *ip;            /* IP header in payload. */
00060         udp_hdr_t       *udp;           /* UDP header in payload. */
00061         udp_io_hdr_t    *udpio;         /* UDP I/O header in payload. */
00062         dhcp_t          *dhcp;          /* DHCP data in payload. */
00063         u8_t            pad[2];         /* buf[] must start at 2 mod 4. */
00064                                         /* Payload: */
00065         u8_t            buf[ETH_MAX_PACK_SIZE];
00066 } buf_t;
00067 
00068 #define BUF_ETH_SIZE    (ETH_MAX_PACK_SIZE)
00069 #define BUF_IP_SIZE     (BUF_ETH_SIZE - sizeof(eth_hdr_t))
00070 #define BUF_UDP_SIZE    (BUF_IP_SIZE - sizeof(ip_hdr_t) - sizeof(udp_hdr_t) \
00071                                 + sizeof(udp_io_hdr_t))
00072 
00073 /* Type of network device open: Ethernet, ICMP, BOOTP client, BOOTP server. */
00074 typedef enum { FT_CLOSED, FT_ETHERNET, FT_ICMP, FT_BOOTPC, FT_BOOTPS } fdtype_t;
00075 
00076 #define FT_ALL  FT_CLOSED       /* To close all open descriptors at once. */
00077 
00078 typedef struct fd {             /* An open descriptor. */
00079         i8_t            fd;             /* Open descriptor. */
00080         u8_t            fdtype;         /* Type of network open. */
00081         char            device[sizeof("/dev/eth###")];  /* Device name. */
00082         u8_t            n;              /* Network that owns it. */
00083         buf_t           *bp;            /* Associated packet buffer. */
00084         time_t          since;          /* Open since when? */
00085 } fd_t;
00086 
00087 /* Network state: Any IP device, Ethernet in sink mode, True Ethernet. */
00088 typedef enum { NT_IP, NT_SINK, NT_ETHERNET } nettype_t;
00089 
00090 typedef struct network {        /* Information on a network. */
00091         u8_t            n;              /* Network number. */
00092         ether_addr_t    eth;            /* Ethernet address of this net. */
00093         u8_t            type;           /* What kind of net is this? */
00094         i8_t            sol_ct;         /* Router solicitation count. */
00095         ether_addr_t    conflict;       /* Address conflict with this one. */
00096         unsigned        flags;          /* Various flags. */
00097         fd_t            *fdp;           /* Current open device. */
00098         struct network  *wait;          /* Wait for a resource list. */
00099         ipaddr_t        ip;             /* IP address of this net. */
00100         ipaddr_t        mask;           /* Associated netmask. */
00101         ipaddr_t        gateway;        /* My router. */
00102         ipaddr_t        server;         /* My DHCP server. */
00103         const char      *hostname;      /* Optional hostname to query for. */
00104         time_t          start;          /* Query or lease start time. */
00105         time_t          delta;          /* Query again after delta seconds. */
00106         time_t          renew;          /* Next query or go into renewal. */
00107         time_t          rebind;         /* When to go into rebind. */
00108         time_t          lease;          /* When our lease expires. */
00109         time_t          solicit;        /* Time to do a router solicitation. */
00110 } network_t;
00111 
00112 /* Flags. */
00113 #define NF_NEGOTIATING  0x001           /* Negotiating with a DHCP server. */
00114 #define NF_BOUND        0x002           /* Address configured through DHCP. */
00115 #define NF_SERVING      0x004           /* I'm a server on this network. */
00116 #define NF_RELAYING     0x008           /* I'm relaying for this network. */
00117 #define NF_WAIT         0x010           /* Wait for a resource to free up. */
00118 #define NF_IRDP         0x020           /* IRDP is used on this net. */
00119 #define NF_CONFLICT     0x040           /* There is an address conflict. */
00120 #define NF_POSSESSIVE   0x080           /* Keep address if lease expires. */
00121 #define NF_INFORM       0x100           /* It's ok to answer DHCPINFORM. */
00122 
00123 /* Functions defined in dhcpd.c. */
00124 void report(const char *label);
00125 void fatal(const char *label);
00126 void *allocate(size_t size);
00127 int ifname2if(const char *name);
00128 network_t *if2net(int n);
00129 
00130 /* Devices.c */
00131 void get_buf(buf_t **bp);
00132 void put_buf(buf_t **bp);
00133 void give_buf(buf_t **dbp, buf_t **sbp);
00134 network_t *newnetwork(void);
00135 void closefd(fd_t *fdp);
00136 int opendev(network_t *np, fdtype_t fdtype, int compete);
00137 void closedev(network_t *np, fdtype_t fdtype);
00138 char *ipdev(int n);
00139 void set_ipconf(char *device, ipaddr_t ip, ipaddr_t mask, unsigned mtu);
00140 
00141 /* Ether.c */
00142 void udp2ether(buf_t *bp, network_t *np);
00143 int ether2udp(buf_t *bp);
00144 void make_arp(buf_t *bp, network_t *np);
00145 int is_arp_me(buf_t *bp, network_t *np);
00146 void icmp_solicit(buf_t *bp);
00147 void icmp_advert(buf_t *bp, network_t *np);
00148 ipaddr_t icmp_is_advert(buf_t *bp);
00149 
00150 /* Tags.c */
00151 #define gettag(dp, st, pd, pl)  dhcp_gettag((dp), (st), (pd), (pl))
00152 void settag(dhcp_t *dp, int tag, void *data, size_t len);
00153 char *cidr_ntoa(ipaddr_t addr, ipaddr_t mask);
00154 void ether2clid(u8_t *clid, ether_addr_t *eth);
00155 void initdhcpconf(void);
00156 int makedhcp(dhcp_t *dp, u8_t *class, size_t calen, u8_t *client, size_t cilen,
00157                                 ipaddr_t ip, ipaddr_t ifip, network_t *np);
00158 char *dhcptypename(int type);
00159 void printdhcp(dhcp_t *dp);

Generated on Fri Apr 14 22:56:47 2006 for minix by  doxygen 1.4.6