1 /* $OpenBSD: dhcpd.h,v 1.11 2007/01/04 19:12:41 stevesk 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 #include <sys/types.h> 43 #include <sys/socket.h> 44 #include <sys/sockio.h> 45 #include <sys/stat.h> 46 #include <sys/time.h> 47 #include <sys/wait.h> 48 49 #include <net/if.h> 50 #include <net/if_dl.h> 51 #include <net/route.h> 52 53 #include <netinet/in.h> 54 #include <arpa/inet.h> 55 56 #include <ctype.h> 57 #include <errno.h> 58 #include <fcntl.h> 59 #include <limits.h> 60 #include <netdb.h> 61 #include <paths.h> 62 #include <pwd.h> 63 #include <stdarg.h> 64 #include <stdio.h> 65 #include <stdlib.h> 66 #include <string.h> 67 #include <syslog.h> 68 #include <time.h> 69 #include <unistd.h> 70 71 #include "dhcp.h" 72 73 #define SERVER_PORT 67 74 #define CLIENT_PORT 68 75 76 struct iaddr { 77 int len; 78 unsigned char iabuf[16]; 79 }; 80 81 struct hardware { 82 u_int8_t htype; 83 u_int8_t hlen; 84 u_int8_t haddr[16]; 85 }; 86 87 /* Possible states in which the client can be. */ 88 enum dhcp_state { 89 S_REBOOTING, 90 S_INIT, 91 S_SELECTING, 92 S_REQUESTING, 93 S_BOUND, 94 S_RENEWING, 95 S_REBINDING 96 }; 97 98 99 struct interface_info { 100 struct interface_info *next; 101 struct hardware hw_address; 102 struct in_addr primary_address; 103 char name[IFNAMSIZ]; 104 int rfdesc; 105 int wfdesc; 106 unsigned char *rbuf; 107 size_t rbuf_max; 108 size_t rbuf_offset; 109 size_t rbuf_len; 110 struct ifreq *ifp; 111 int noifmedia; 112 int errors; 113 int dead; 114 u_int16_t index; 115 }; 116 117 struct timeout { 118 struct timeout *next; 119 time_t when; 120 void (*func)(void *); 121 void *what; 122 }; 123 124 struct protocol { 125 struct protocol *next; 126 int fd; 127 void (*handler)(struct protocol *); 128 void *local; 129 }; 130 131 #define DHCPD_LOG_FACILITY LOG_DAEMON 132 133 /* External definitions... */ 134 135 /* errwarn.c */ 136 void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 137 int warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 138 int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 139 int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); 140 141 /* bpf.c */ 142 int if_register_bpf(struct interface_info *); 143 void if_register_send(struct interface_info *); 144 void if_register_receive(struct interface_info *); 145 ssize_t send_packet(struct interface_info *, 146 struct dhcp_packet *, size_t, struct in_addr, 147 struct sockaddr_in *, struct hardware *); 148 ssize_t receive_packet(struct interface_info *, unsigned char *, size_t, 149 struct sockaddr_in *, struct hardware *); 150 151 /* dispatch.c */ 152 extern void (*bootp_packet_handler)(struct interface_info *, 153 struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *); 154 void discover_interfaces(struct interface_info *); 155 void dispatch(void); 156 void got_one(struct protocol *); 157 void add_protocol(char *, int, void (*)(struct protocol *), void *); 158 void remove_protocol(struct protocol *); 159 160 /* packet.c */ 161 void assemble_hw_header(struct interface_info *, unsigned char *, 162 int *, struct hardware *); 163 void assemble_udp_ip_header(struct interface_info *, unsigned char *, 164 int *, u_int32_t, u_int32_t, unsigned int, unsigned char *, int); 165 ssize_t decode_hw_header(struct interface_info *, unsigned char *, 166 int, struct hardware *); 167 ssize_t decode_udp_ip_header(struct interface_info *, unsigned char *, 168 int, struct sockaddr_in *, unsigned char *, int); 169 170 /* dhcrelay.c */ 171 extern u_int16_t server_port; 172 extern u_int16_t client_port; 173 174 /* crap */ 175 extern time_t cur_time; 176 extern int log_priority; 177 extern int log_perror; 178