dhcpd.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* vi: set sw=4 ts=4: */
  2. /* dhcpd.h */
  3. #ifndef _DHCPD_H
  4. #define _DHCPD_H
  5. /************************************/
  6. /* Defaults _you_ may want to tweak */
  7. /************************************/
  8. /* the period of time the client is allowed to use that address */
  9. #define LEASE_TIME (60*60*24*10) /* 10 days of seconds */
  10. #define LEASES_FILE "/var/lib/misc/udhcpd.leases"
  11. /* where to find the DHCP server configuration file */
  12. #define DHCPD_CONF_FILE "/etc/udhcpd.conf"
  13. /*****************************************************************/
  14. /* Do not modify below here unless you know what you are doing!! */
  15. /*****************************************************************/
  16. /* DHCP protocol -- see RFC 2131 */
  17. #define SERVER_PORT 67
  18. #define CLIENT_PORT 68
  19. #define DHCP_MAGIC 0x63825363
  20. /* DHCP option codes (partial list) */
  21. #define DHCP_PADDING 0x00
  22. #define DHCP_SUBNET 0x01
  23. #define DHCP_TIME_OFFSET 0x02
  24. #define DHCP_ROUTER 0x03
  25. #define DHCP_TIME_SERVER 0x04
  26. #define DHCP_NAME_SERVER 0x05
  27. #define DHCP_DNS_SERVER 0x06
  28. #define DHCP_LOG_SERVER 0x07
  29. #define DHCP_COOKIE_SERVER 0x08
  30. #define DHCP_LPR_SERVER 0x09
  31. #define DHCP_HOST_NAME 0x0c
  32. #define DHCP_BOOT_SIZE 0x0d
  33. #define DHCP_DOMAIN_NAME 0x0f
  34. #define DHCP_SWAP_SERVER 0x10
  35. #define DHCP_ROOT_PATH 0x11
  36. #define DHCP_IP_TTL 0x17
  37. #define DHCP_MTU 0x1a
  38. #define DHCP_BROADCAST 0x1c
  39. #define DHCP_NTP_SERVER 0x2a
  40. #define DHCP_WINS_SERVER 0x2c
  41. #define DHCP_REQUESTED_IP 0x32
  42. #define DHCP_LEASE_TIME 0x33
  43. #define DHCP_OPTION_OVER 0x34
  44. #define DHCP_MESSAGE_TYPE 0x35
  45. #define DHCP_SERVER_ID 0x36
  46. #define DHCP_PARAM_REQ 0x37
  47. #define DHCP_MESSAGE 0x38
  48. #define DHCP_MAX_SIZE 0x39
  49. #define DHCP_T1 0x3a
  50. #define DHCP_T2 0x3b
  51. #define DHCP_VENDOR 0x3c
  52. #define DHCP_CLIENT_ID 0x3d
  53. #define DHCP_FQDN 0x51
  54. #define DHCP_END 0xFF
  55. #define BOOTREQUEST 1
  56. #define BOOTREPLY 2
  57. #define ETH_10MB 1
  58. #define ETH_10MB_LEN 6
  59. #define DHCPDISCOVER 1
  60. #define DHCPOFFER 2
  61. #define DHCPREQUEST 3
  62. #define DHCPDECLINE 4
  63. #define DHCPACK 5
  64. #define DHCPNAK 6
  65. #define DHCPRELEASE 7
  66. #define DHCPINFORM 8
  67. #define BROADCAST_FLAG 0x8000
  68. #define OPTION_FIELD 0
  69. #define FILE_FIELD 1
  70. #define SNAME_FIELD 2
  71. /* miscellaneous defines */
  72. #define MAC_BCAST_ADDR (uint8_t *) "\xff\xff\xff\xff\xff\xff"
  73. #define OPT_CODE 0
  74. #define OPT_LEN 1
  75. #define OPT_DATA 2
  76. struct option_set {
  77. uint8_t *data;
  78. struct option_set *next;
  79. };
  80. struct static_lease {
  81. uint8_t *mac;
  82. uint32_t *ip;
  83. struct static_lease *next;
  84. };
  85. struct server_config_t {
  86. uint32_t server; /* Our IP, in network order */
  87. uint32_t start; /* Start address of leases, network order */
  88. uint32_t end; /* End of leases, network order */
  89. struct option_set *options; /* List of DHCP options loaded from the config file */
  90. char *interface; /* The name of the interface to use */
  91. int ifindex; /* Index number of the interface to use */
  92. uint8_t arp[6]; /* Our arp address */
  93. unsigned long lease; /* lease time in seconds (host order) */
  94. unsigned long max_leases; /* maximum number of leases (including reserved address) */
  95. char remaining; /* should the lease file be interpreted as lease time remaining, or
  96. * as the time the lease expires */
  97. unsigned long auto_time; /* how long should udhcpd wait before writing a config file.
  98. * if this is zero, it will only write one on SIGUSR1 */
  99. unsigned long decline_time; /* how long an address is reserved if a client returns a
  100. * decline message */
  101. unsigned long conflict_time; /* how long an arp conflict offender is leased for */
  102. unsigned long offer_time; /* how long an offered address is reserved */
  103. unsigned long min_lease; /* minimum lease a client can request*/
  104. char *lease_file;
  105. char *pidfile;
  106. char *notify_file; /* What to run whenever leases are written */
  107. uint32_t siaddr; /* next server bootp option */
  108. char *sname; /* bootp server name */
  109. char *boot_file; /* bootp boot file option */
  110. struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */
  111. };
  112. extern struct server_config_t server_config;
  113. extern struct dhcpOfferedAddr *leases;
  114. /*** leases.h ***/
  115. struct dhcpOfferedAddr {
  116. uint8_t chaddr[16];
  117. uint32_t yiaddr; /* network order */
  118. uint32_t expires; /* host order */
  119. };
  120. extern uint8_t blank_chaddr[];
  121. void clear_lease(uint8_t *chaddr, uint32_t yiaddr);
  122. struct dhcpOfferedAddr *add_lease(uint8_t *chaddr, uint32_t yiaddr, unsigned long lease);
  123. int lease_expired(struct dhcpOfferedAddr *lease);
  124. struct dhcpOfferedAddr *oldest_expired_lease(void);
  125. struct dhcpOfferedAddr *find_lease_by_chaddr(uint8_t *chaddr);
  126. struct dhcpOfferedAddr *find_lease_by_yiaddr(uint32_t yiaddr);
  127. uint32_t find_address(int check_expired);
  128. /*** static_leases.h ***/
  129. /* Config file will pass static lease info to this function which will add it
  130. * to a data structure that can be searched later */
  131. int addStaticLease(struct static_lease **lease_struct, uint8_t *mac, uint32_t *ip);
  132. /* Check to see if a mac has an associated static lease */
  133. uint32_t getIpByMac(struct static_lease *lease_struct, void *arg);
  134. /* Check to see if an ip is reserved as a static ip */
  135. uint32_t reservedIp(struct static_lease *lease_struct, uint32_t ip);
  136. /* Print out static leases just to check what's going on (debug code) */
  137. void printStaticLeases(struct static_lease **lease_struct);
  138. /*** serverpacket.h ***/
  139. int sendOffer(struct dhcpMessage *oldpacket);
  140. int sendNAK(struct dhcpMessage *oldpacket);
  141. int sendACK(struct dhcpMessage *oldpacket, uint32_t yiaddr);
  142. int send_inform(struct dhcpMessage *oldpacket);
  143. /*** files.h ***/
  144. struct config_keyword {
  145. const char *keyword;
  146. int (* const handler)(const char *line, void *var);
  147. void *var;
  148. const char *def;
  149. };
  150. int read_config(const char *file);
  151. void write_leases(void);
  152. void read_leases(const char *file);
  153. struct option_set *find_option(struct option_set *opt_list, char code);
  154. #endif