Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 1 | /* dhcpd.h */ |
| 2 | #ifndef _DHCPD_H |
| 3 | #define _DHCPD_H |
| 4 | |
| 5 | #include <netinet/ip.h> |
| 6 | #include <netinet/udp.h> |
| 7 | |
Russ Dill | 8b38451 | 2003-12-16 02:30:53 +0000 | [diff] [blame] | 8 | #include "libbb_udhcp.h" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 9 | #include "leases.h" |
Russ Dill | 8b38451 | 2003-12-16 02:30:53 +0000 | [diff] [blame] | 10 | #include "version.h" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 11 | |
| 12 | /************************************/ |
| 13 | /* Defaults _you_ may want to tweak */ |
| 14 | /************************************/ |
| 15 | |
| 16 | /* the period of time the client is allowed to use that address */ |
| 17 | #define LEASE_TIME (60*60*24*10) /* 10 days of seconds */ |
Russ Dill | 8b38451 | 2003-12-16 02:30:53 +0000 | [diff] [blame] | 18 | #define LEASES_FILE "/var/lib/misc/udhcpd.leases" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 19 | |
| 20 | /* where to find the DHCP server configuration file */ |
| 21 | #define DHCPD_CONF_FILE "/etc/udhcpd.conf" |
| 22 | |
| 23 | /*****************************************************************/ |
| 24 | /* Do not modify below here unless you know what you are doing!! */ |
| 25 | /*****************************************************************/ |
| 26 | |
| 27 | /* DHCP protocol -- see RFC 2131 */ |
| 28 | #define SERVER_PORT 67 |
| 29 | #define CLIENT_PORT 68 |
| 30 | |
| 31 | #define DHCP_MAGIC 0x63825363 |
| 32 | |
| 33 | /* DHCP option codes (partial list) */ |
| 34 | #define DHCP_PADDING 0x00 |
| 35 | #define DHCP_SUBNET 0x01 |
| 36 | #define DHCP_TIME_OFFSET 0x02 |
| 37 | #define DHCP_ROUTER 0x03 |
| 38 | #define DHCP_TIME_SERVER 0x04 |
| 39 | #define DHCP_NAME_SERVER 0x05 |
| 40 | #define DHCP_DNS_SERVER 0x06 |
| 41 | #define DHCP_LOG_SERVER 0x07 |
| 42 | #define DHCP_COOKIE_SERVER 0x08 |
| 43 | #define DHCP_LPR_SERVER 0x09 |
| 44 | #define DHCP_HOST_NAME 0x0c |
| 45 | #define DHCP_BOOT_SIZE 0x0d |
| 46 | #define DHCP_DOMAIN_NAME 0x0f |
| 47 | #define DHCP_SWAP_SERVER 0x10 |
| 48 | #define DHCP_ROOT_PATH 0x11 |
| 49 | #define DHCP_IP_TTL 0x17 |
| 50 | #define DHCP_MTU 0x1a |
| 51 | #define DHCP_BROADCAST 0x1c |
| 52 | #define DHCP_NTP_SERVER 0x2a |
| 53 | #define DHCP_WINS_SERVER 0x2c |
| 54 | #define DHCP_REQUESTED_IP 0x32 |
| 55 | #define DHCP_LEASE_TIME 0x33 |
| 56 | #define DHCP_OPTION_OVER 0x34 |
| 57 | #define DHCP_MESSAGE_TYPE 0x35 |
| 58 | #define DHCP_SERVER_ID 0x36 |
| 59 | #define DHCP_PARAM_REQ 0x37 |
| 60 | #define DHCP_MESSAGE 0x38 |
| 61 | #define DHCP_MAX_SIZE 0x39 |
| 62 | #define DHCP_T1 0x3a |
| 63 | #define DHCP_T2 0x3b |
| 64 | #define DHCP_VENDOR 0x3c |
| 65 | #define DHCP_CLIENT_ID 0x3d |
Mike Frysinger | d824853 | 2004-12-06 14:59:45 +0000 | [diff] [blame] | 66 | #define DHCP_FQDN 0x51 |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 67 | |
| 68 | #define DHCP_END 0xFF |
| 69 | |
| 70 | |
| 71 | #define BOOTREQUEST 1 |
| 72 | #define BOOTREPLY 2 |
| 73 | |
| 74 | #define ETH_10MB 1 |
| 75 | #define ETH_10MB_LEN 6 |
| 76 | |
| 77 | #define DHCPDISCOVER 1 |
| 78 | #define DHCPOFFER 2 |
| 79 | #define DHCPREQUEST 3 |
| 80 | #define DHCPDECLINE 4 |
| 81 | #define DHCPACK 5 |
| 82 | #define DHCPNAK 6 |
| 83 | #define DHCPRELEASE 7 |
| 84 | #define DHCPINFORM 8 |
| 85 | |
| 86 | #define BROADCAST_FLAG 0x8000 |
| 87 | |
| 88 | #define OPTION_FIELD 0 |
| 89 | #define FILE_FIELD 1 |
| 90 | #define SNAME_FIELD 2 |
| 91 | |
| 92 | /* miscellaneous defines */ |
Eric Andersen | ad95373 | 2004-01-30 23:45:53 +0000 | [diff] [blame] | 93 | #define MAC_BCAST_ADDR (uint8_t *) "\xff\xff\xff\xff\xff\xff" |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 94 | #define OPT_CODE 0 |
| 95 | #define OPT_LEN 1 |
| 96 | #define OPT_DATA 2 |
| 97 | |
| 98 | struct option_set { |
Eric Andersen | ad95373 | 2004-01-30 23:45:53 +0000 | [diff] [blame] | 99 | uint8_t *data; |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 100 | struct option_set *next; |
| 101 | }; |
| 102 | |
Eric Andersen | abf58d6 | 2004-10-08 08:49:26 +0000 | [diff] [blame] | 103 | struct static_lease { |
| 104 | uint8_t *mac; |
| 105 | uint32_t *ip; |
| 106 | struct static_lease *next; |
| 107 | }; |
| 108 | |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 109 | struct server_config_t { |
Eric Andersen | ad95373 | 2004-01-30 23:45:53 +0000 | [diff] [blame] | 110 | uint32_t server; /* Our IP, in network order */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 111 | uint32_t start; /* Start address of leases, network order */ |
Eric Andersen | ad95373 | 2004-01-30 23:45:53 +0000 | [diff] [blame] | 112 | uint32_t end; /* End of leases, network order */ |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 113 | struct option_set *options; /* List of DHCP options loaded from the config file */ |
| 114 | char *interface; /* The name of the interface to use */ |
| 115 | int ifindex; /* Index number of the interface to use */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 116 | uint8_t arp[6]; /* Our arp address */ |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 117 | unsigned long lease; /* lease time in seconds (host order) */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 118 | unsigned long max_leases; /* maximum number of leases (including reserved address) */ |
| 119 | char remaining; /* should the lease file be interpreted as lease time remaining, or |
| 120 | * as the time the lease expires */ |
| 121 | unsigned long auto_time; /* how long should udhcpd wait before writing a config file. |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 122 | * if this is zero, it will only write one on SIGUSR1 */ |
Tim Riker | c1ef7bd | 2006-01-25 00:08:53 +0000 | [diff] [blame] | 123 | unsigned long decline_time; /* how long an address is reserved if a client returns a |
| 124 | * decline message */ |
| 125 | unsigned long conflict_time; /* how long an arp conflict offender is leased for */ |
| 126 | unsigned long offer_time; /* how long an offered address is reserved */ |
| 127 | unsigned long min_lease; /* minimum lease a client can request*/ |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 128 | char *lease_file; |
| 129 | char *pidfile; |
| 130 | char *notify_file; /* What to run whenever leases are written */ |
Eric Andersen | ad95373 | 2004-01-30 23:45:53 +0000 | [diff] [blame] | 131 | uint32_t siaddr; /* next server bootp option */ |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 132 | char *sname; /* bootp server name */ |
| 133 | char *boot_file; /* bootp boot file option */ |
Eric Andersen | abf58d6 | 2004-10-08 08:49:26 +0000 | [diff] [blame] | 134 | struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */ |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 135 | }; |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 136 | |
| 137 | extern struct server_config_t server_config; |
| 138 | extern struct dhcpOfferedAddr *leases; |
Eric Andersen | c7bda1c | 2004-03-15 08:29:22 +0000 | [diff] [blame] | 139 | |
Russ Dill | 61fb489 | 2002-10-14 21:41:28 +0000 | [diff] [blame] | 140 | |
| 141 | #endif |