1 /* $OpenBSD: dhcpd.h,v 1.14 2016/02/07 00:49:28 krw Exp $ */ 2 3 /* 4 * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> 5 * Copyright (c) 1995, 1996, 1997, 1998, 1999 6 * The Internet Software Consortium. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of The Internet Software Consortium nor the names 18 * of its contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND 22 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 * DISCLAIMED. IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR 26 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 29 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * This software has been written for the Internet Software Consortium 36 * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie 37 * Enterprises. To learn more about the Internet Software Consortium, 38 * see ``http://www.vix.com/isc''. To learn more about Vixie 39 * Enterprises, see ``http://www.vix.com''. 40 */ 41 42 #define SERVER_PORT 67 43 #define CLIENT_PORT 68 44 45 struct iaddr { 46 int len; 47 unsigned char iabuf[16]; 48 }; 49 50 struct hardware { 51 u_int8_t htype; 52 u_int8_t hlen; 53 u_int8_t haddr[16]; 54 }; 55 56 /* Possible states in which the client can be. */ 57 enum dhcp_state { 58 S_REBOOTING, 59 S_INIT, 60 S_SELECTING, 61 S_REQUESTING, 62 S_BOUND, 63 S_RENEWING, 64 S_REBINDING 65 }; 66 67 68 struct interface_info { 69 struct interface_info *next; 70 struct hardware hw_address; 71 struct in_addr primary_address; 72 char name[IFNAMSIZ]; 73 int rfdesc; 74 int wfdesc; 75 unsigned char *rbuf; 76 size_t rbuf_max; 77 size_t rbuf_offset; 78 size_t rbuf_len; 79 struct ifreq *ifp; 80 int noifmedia; 81 int errors; 82 int dead; 83 u_int16_t index; 84 }; 85 86 struct timeout { 87 struct timeout *next; 88 time_t when; 89 void (*func)(void *); 90 void *what; 91 }; 92 93 struct protocol { 94 struct protocol *next; 95 int fd; 96 void (*handler)(struct protocol *); 97 void *local; 98 }; 99 100 #define DHCPD_LOG_FACILITY LOG_DAEMON 101 102 /* External definitions... */ 103 104 /* errwarn.c */ 105 void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 106 int warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 107 int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 108 int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 109 110 /* bpf.c */ 111 int if_register_bpf(struct interface_info *); 112 void if_register_send(struct interface_info *); 113 void if_register_receive(struct interface_info *); 114 ssize_t send_packet(struct interface_info *, 115 struct dhcp_packet *, size_t, struct in_addr, 116 struct sockaddr_in *, struct hardware *); 117 ssize_t receive_packet(struct interface_info *, unsigned char *, size_t, 118 struct sockaddr_in *, struct hardware *); 119 120 /* dispatch.c */ 121 extern void (*bootp_packet_handler)(struct interface_info *, 122 struct dhcp_packet *, int, unsigned int, struct iaddr, 123 struct hardware *); 124 void discover_interfaces(struct interface_info *); 125 void dispatch(void); 126 void got_one(struct protocol *); 127 void add_protocol(char *, int, void (*)(struct protocol *), void *); 128 void remove_protocol(struct protocol *); 129 130 /* packet.c */ 131 void assemble_hw_header(struct interface_info *, unsigned char *, 132 int *, struct hardware *); 133 void assemble_udp_ip_header(struct interface_info *, unsigned char *, 134 int *, u_int32_t, u_int32_t, unsigned int, unsigned char *, int); 135 ssize_t decode_hw_header(struct interface_info *, unsigned char *, 136 int, struct hardware *); 137 ssize_t decode_udp_ip_header(struct interface_info *, unsigned char *, 138 int, struct sockaddr_in *, int); 139 140 /* dhcrelay.c */ 141 extern u_int16_t server_port; 142 extern u_int16_t client_port; 143 extern int server_fd; 144 145 /* crap */ 146 extern time_t cur_time; 147 extern int log_priority; 148 extern int log_perror; 149