ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

dhcpd.h
Go to the documentation of this file.
00001 /*  $OpenBSD: dhcpd.h,v 1.33 2004/05/06 22:29:15 deraadt Exp $  */
00002 
00003 /*
00004  * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
00005  * Copyright (c) 1995, 1996, 1997, 1998, 1999
00006  * The Internet Software Consortium.    All rights reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the distribution.
00017  * 3. Neither the name of The Internet Software Consortium nor the names
00018  *    of its contributors may be used to endorse or promote products derived
00019  *    from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE INTERNET SOFTWARE CONSORTIUM AND
00022  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
00023  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00024  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00025  * DISCLAIMED.  IN NO EVENT SHALL THE INTERNET SOFTWARE CONSORTIUM OR
00026  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00027  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00028  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00029  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00030  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00031  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00032  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00033  * SUCH DAMAGE.
00034  *
00035  * This software has been written for the Internet Software Consortium
00036  * by Ted Lemon <mellon@fugue.com> in cooperation with Vixie
00037  * Enterprises.  To learn more about the Internet Software Consortium,
00038  * see ``http://www.vix.com/isc''.  To learn more about Vixie
00039  * Enterprises, see ``http://www.vix.com''.
00040  */
00041 
00042 #pragma once
00043 
00044 #include <winsock2.h>
00045 #include <iphlpapi.h>
00046 #include "stdint.h"
00047 
00048 #define IFNAMSIZ MAX_INTERFACE_NAME_LEN
00049 
00050 #define ETH_ALEN 6
00051 #define ETHER_ADDR_LEN  ETH_ALEN
00052 #include <pshpack1.h>
00053 struct ether_header
00054 {
00055   u_int8_t  ether_dhost[ETH_ALEN];      /* destination eth addr */
00056   u_int8_t  ether_shost[ETH_ALEN];      /* source ether addr    */
00057   u_int16_t ether_type;                 /* packet type ID field */
00058 };
00059 #include <poppack.h>
00060 
00061 struct ip
00062   {
00063     unsigned int ip_hl:4;               /* header length */
00064     unsigned int ip_v:4;                /* version */
00065     u_int8_t ip_tos;                    /* type of service */
00066     u_short ip_len;                     /* total length */
00067     u_short ip_id;                      /* identification */
00068     u_short ip_off;                     /* fragment offset field */
00069 #define IP_RF 0x8000                    /* reserved fragment flag */
00070 #define IP_DF 0x4000                    /* dont fragment flag */
00071 #define IP_MF 0x2000                    /* more fragments flag */
00072 #define IP_OFFMASK 0x1fff               /* mask for fragmenting bits */
00073     u_int8_t ip_ttl;                    /* time to live */
00074     u_int8_t ip_p;                      /* protocol */
00075     u_short ip_sum;                     /* checksum */
00076     struct in_addr ip_src, ip_dst;      /* source and dest address */
00077   };
00078 
00079 struct udphdr {
00080     u_int16_t uh_sport;           /* source port */
00081     u_int16_t uh_dport;           /* destination port */
00082     u_int16_t uh_ulen;            /* udp length */
00083     u_int16_t uh_sum;             /* udp checksum */
00084 };
00085 
00086 #define ETHERTYPE_IP 0x0800
00087 #define IPTOS_LOWDELAY 0x10
00088 #define ARPHRD_ETHER 1
00089 
00090 // FIXME: I have no idea what this should be!
00091 #define SIZE_T_MAX 1600
00092 
00093 #define USE_SOCKET_RECEIVE
00094 #define USE_SOCKET_SEND
00095 
00096 #include <sys/types.h>
00097 #include <sys/stat.h>
00098 //#include <sys/time.h>
00099 #include <ctype.h>
00100 #include <fcntl.h>
00101 #include <limits.h>
00102 //#include <unistd.h>
00103 #include <stdio.h>
00104 #include <stdlib.h>
00105 #include <string.h>
00106 #include <time.h>
00107 //#include <unistd.h>
00108 
00109 #include "dhcp.h"
00110 #include "tree.h"
00111 
00112 #define LOCAL_PORT  68
00113 #define REMOTE_PORT 67
00114 
00115 struct option_data {
00116     int      len;
00117     u_int8_t    *data;
00118 };
00119 
00120 struct string_list {
00121     struct string_list  *next;
00122     char            *string;
00123 };
00124 
00125 struct iaddr {
00126     int len;
00127     unsigned char iabuf[16];
00128 };
00129 
00130 struct iaddrlist {
00131     struct iaddrlist *next;
00132     struct iaddr addr;
00133 };
00134 
00135 struct packet {
00136     struct dhcp_packet  *raw;
00137     int          packet_length;
00138     int          packet_type;
00139     int          options_valid;
00140     int          client_port;
00141     struct iaddr         client_addr;
00142     struct interface_info   *interface;
00143     struct hardware     *haddr;
00144     struct option_data   options[256];
00145 };
00146 
00147 struct hardware {
00148     u_int8_t htype;
00149     u_int8_t hlen;
00150     u_int8_t haddr[16];
00151 };
00152 
00153 struct client_lease {
00154     struct client_lease *next;
00155     time_t           expiry, renewal, rebind;
00156     struct iaddr         address;
00157     char            *server_name;
00158 #ifdef __REACTOS__
00159     time_t           obtained;
00160     struct iaddr         serveraddress;
00161 #endif
00162     char            *filename;
00163     struct string_list  *medium;
00164     unsigned int         is_static : 1;
00165     unsigned int         is_bootp : 1;
00166     struct option_data   options[256];
00167 };
00168 
00169 /* Possible states in which the client can be. */
00170 enum dhcp_state {
00171     S_REBOOTING,
00172     S_INIT,
00173     S_SELECTING,
00174     S_REQUESTING,
00175     S_BOUND,
00176     S_RENEWING,
00177     S_REBINDING,
00178     S_STATIC
00179 };
00180 
00181 struct client_config {
00182     struct option_data  defaults[256];
00183     enum {
00184         ACTION_DEFAULT,
00185         ACTION_SUPERSEDE,
00186         ACTION_PREPEND,
00187         ACTION_APPEND
00188     } default_actions[256];
00189 
00190     struct option_data   send_options[256];
00191     u_int8_t         required_options[256];
00192     u_int8_t         requested_options[256];
00193     int          requested_option_count;
00194     time_t           timeout;
00195     time_t           initial_interval;
00196     time_t           retry_interval;
00197     time_t           select_interval;
00198     time_t           reboot_timeout;
00199     time_t           backoff_cutoff;
00200     struct string_list  *media;
00201     char            *script_name;
00202     enum { IGNORE, ACCEPT, PREFER }
00203                  bootp_policy;
00204     struct string_list  *medium;
00205     struct iaddrlist    *reject_list;
00206 };
00207 
00208 struct client_state {
00209     struct client_lease  *active;
00210     struct client_lease  *new;
00211     struct client_lease  *offered_leases;
00212     struct client_lease  *leases;
00213     struct client_lease  *alias;
00214     enum dhcp_state       state;
00215     struct iaddr          destination;
00216     u_int32_t         xid;
00217     u_int16_t         secs;
00218     time_t            first_sending;
00219     time_t            interval;
00220     struct string_list   *medium;
00221     struct dhcp_packet    packet;
00222     int           packet_length;
00223     struct iaddr          requested_address;
00224     struct client_config     *config;
00225 };
00226 
00227 struct interface_info {
00228     struct interface_info   *next;
00229     struct hardware      hw_address;
00230     struct in_addr       primary_address;
00231     char             name[IFNAMSIZ];
00232     int          rfdesc;
00233     int          wfdesc;
00234     unsigned char       *rbuf;
00235     size_t           rbuf_max;
00236     size_t           rbuf_offset;
00237     size_t           rbuf_len;
00238     struct client_state *client;
00239     int          noifmedia;
00240     int          errors;
00241     int          dead;
00242     u_int16_t        index;
00243 };
00244 
00245 struct timeout {
00246     struct timeout  *next;
00247     time_t       when;
00248     void         (*func)(void *);
00249     void        *what;
00250 };
00251 
00252 struct protocol {
00253     struct protocol *next;
00254     int fd;
00255     void (*handler)(struct protocol *);
00256     void *local;
00257 };
00258 
00259 #define DEFAULT_HASH_SIZE 97
00260 
00261 struct hash_bucket {
00262     struct hash_bucket *next;
00263     unsigned char *name;
00264     int len;
00265     unsigned char *value;
00266 };
00267 
00268 struct hash_table {
00269     int hash_count;
00270     struct hash_bucket *buckets[DEFAULT_HASH_SIZE];
00271 };
00272 
00273 /* Default path to dhcpd config file. */
00274 #define _PATH_DHCLIENT_CONF "/etc/dhclient.conf"
00275 #define _PATH_DHCLIENT_DB   "/var/db/dhclient.leases"
00276 #define DHCPD_LOG_FACILITY  LOG_DAEMON
00277 
00278 #define MAX_TIME 0x7fffffff
00279 #define MIN_TIME 0
00280 
00281 /* External definitions... */
00282 
00283 /* options.c */
00284 int cons_options(struct packet *, struct dhcp_packet *, int,
00285     struct tree_cache **, int, int, int, u_int8_t *, int);
00286 char *pretty_print_option(unsigned int,
00287     unsigned char *, int, int, int);
00288 void do_packet(struct interface_info *, struct dhcp_packet *,
00289     int, unsigned int, struct iaddr, struct hardware *);
00290 
00291 /* errwarn.c */
00292 extern int warnings_occurred;
00293 #ifdef _MSC_VER
00294 void error(char *, ...);
00295 int warning(char *, ...);
00296 int note(char *, ...);
00297 int debug(char *, ...);
00298 int parse_warn(char *, ...);
00299 #else
00300 void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
00301 int warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
00302 int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
00303 int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
00304 int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)));
00305 #endif
00306 
00307 /* conflex.c */
00308 extern int lexline, lexchar;
00309 extern char *token_line, *tlname;
00310 extern char comments[4096];
00311 extern int comment_index;
00312 extern int eol_token;
00313 void new_parse(char *);
00314 int next_token(char **, FILE *);
00315 int peek_token(char **, FILE *);
00316 
00317 /* parse.c */
00318 void skip_to_semi(FILE *);
00319 int parse_semi(FILE *);
00320 char *parse_string(FILE *);
00321 int parse_ip_addr(FILE *, struct iaddr *);
00322 void parse_hardware_param(FILE *, struct hardware *);
00323 void parse_lease_time(FILE *, time_t *);
00324 unsigned char *parse_numeric_aggregate(FILE *, unsigned char *, int *,
00325     int, int, int);
00326 void convert_num(unsigned char *, char *, int, int);
00327 time_t parse_date(FILE *);
00328 
00329 /* tree.c */
00330 pair cons(caddr_t, pair);
00331 
00332 /* alloc.c */
00333 struct string_list  *new_string_list(size_t size);
00334 struct hash_table   *new_hash_table(int);
00335 struct hash_bucket  *new_hash_bucket(void);
00336 void dfree(void *, char *);
00337 void free_hash_bucket(struct hash_bucket *, char *);
00338 
00339 
00340 /* bpf.c */
00341 int if_register_bpf(struct interface_info *);
00342 void if_register_send(struct interface_info *);
00343 void if_register_receive(struct interface_info *);
00344 ssize_t send_packet(struct interface_info *, struct dhcp_packet *, size_t,
00345     struct in_addr, struct sockaddr_in *, struct hardware *);
00346 ssize_t receive_packet(struct interface_info *, unsigned char *, size_t,
00347     struct sockaddr_in *, struct hardware *);
00348 
00349 /* dispatch.c */
00350 extern void (*bootp_packet_handler)(struct interface_info *,
00351     struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *);
00352 void discover_interfaces(struct interface_info *);
00353 void reinitialize_interfaces(void);
00354 void dispatch(void);
00355 void got_one(struct protocol *);
00356 void add_timeout(time_t, void (*)(void *), void *);
00357 void cancel_timeout(void (*)(void *), void *);
00358 void add_protocol(char *, int, void (*)(struct protocol *), void *);
00359 void remove_protocol(struct protocol *);
00360 struct protocol *find_protocol_by_adapter( struct interface_info * );
00361 int interface_link_status(char *);
00362 
00363 /* hash.c */
00364 struct hash_table *new_hash(void);
00365 void add_hash(struct hash_table *, unsigned char *, int, unsigned char *);
00366 unsigned char *hash_lookup(struct hash_table *, unsigned char *, int);
00367 
00368 /* tables.c */
00369 extern struct dhcp_option dhcp_options[256];
00370 extern unsigned char dhcp_option_default_priority_list[];
00371 extern int sizeof_dhcp_option_default_priority_list;
00372 extern struct hash_table universe_hash;
00373 extern struct universe dhcp_universe;
00374 void initialize_universes(void);
00375 
00376 /* convert.c */
00377 u_int32_t getULong(unsigned char *);
00378 int32_t getLong(unsigned char *);
00379 u_int16_t getUShort(unsigned char *);
00380 int16_t getShort(unsigned char *);
00381 void putULong(unsigned char *, u_int32_t);
00382 void putLong(unsigned char *, int32_t);
00383 void putUShort(unsigned char *, unsigned int);
00384 void putShort(unsigned char *, int);
00385 
00386 /* inet.c */
00387 struct iaddr subnet_number(struct iaddr, struct iaddr);
00388 struct iaddr broadcast_addr(struct iaddr, struct iaddr);
00389 int addr_eq(struct iaddr, struct iaddr);
00390 char *piaddr(struct iaddr);
00391 
00392 /* dhclient.c */
00393 extern char *path_dhclient_conf;
00394 extern char *path_dhclient_db;
00395 extern time_t cur_time;
00396 extern int log_priority;
00397 extern int log_perror;
00398 
00399 extern struct client_config top_level_config;
00400 
00401 void dhcpoffer(struct packet *);
00402 void dhcpack(struct packet *);
00403 void dhcpnak(struct packet *);
00404 
00405 void send_discover(void *);
00406 void send_request(void *);
00407 void send_decline(void *);
00408 
00409 void state_reboot(void *);
00410 void state_init(void *);
00411 void state_selecting(void *);
00412 void state_requesting(void *);
00413 void state_bound(void *);
00414 void state_panic(void *);
00415 
00416 void bind_lease(struct interface_info *);
00417 
00418 void make_discover(struct interface_info *, struct client_lease *);
00419 void make_request(struct interface_info *, struct client_lease *);
00420 void make_decline(struct interface_info *, struct client_lease *);
00421 
00422 void free_client_lease(struct client_lease *);
00423 void rewrite_client_leases(struct interface_info *);
00424 void write_client_lease(struct interface_info *, struct client_lease *, int);
00425 
00426 void     priv_script_init(struct interface_info *, char *, char *);
00427 void     priv_script_write_params(struct interface_info *, char *, struct client_lease *);
00428 int  priv_script_go(void);
00429 
00430 void script_init(char *, struct string_list *);
00431 void script_write_params(char *, struct client_lease *);
00432 int script_go(void);
00433 void client_envadd(struct client_state *,
00434     const char *, const char *, const char *, ...);
00435 void script_set_env(struct client_state *, const char *, const char *,
00436     const char *);
00437 void script_flush_env(struct client_state *);
00438 int dhcp_option_ev_name(char *, size_t, struct dhcp_option *);
00439 
00440 struct client_lease *packet_to_lease(struct packet *);
00441 void go_daemon(void);
00442 void client_location_changed(void);
00443 
00444 void bootp(struct packet *);
00445 void dhcp(struct packet *);
00446 
00447 /* packet.c */
00448 void assemble_hw_header(struct interface_info *, unsigned char *,
00449     int *, struct hardware *);
00450 void assemble_udp_ip_header(unsigned char *, int *, u_int32_t, u_int32_t,
00451     unsigned int, unsigned char *, int);
00452 ssize_t decode_hw_header(unsigned char *, int, struct hardware *);
00453 ssize_t decode_udp_ip_header(unsigned char *, int, struct sockaddr_in *,
00454     unsigned char *, int);
00455 
00456 /* ethernet.c */
00457 void assemble_ethernet_header(struct interface_info *, unsigned char *,
00458     int *, struct hardware *);
00459 ssize_t decode_ethernet_header(struct interface_info *, unsigned char *,
00460     int, struct hardware *);
00461 
00462 /* clparse.c */
00463 int read_client_conf(struct interface_info *);
00464 void read_client_leases(void);
00465 void parse_client_statement(FILE *, struct interface_info *,
00466     struct client_config *);
00467 int parse_X(FILE *, u_int8_t *, int);
00468 int parse_option_list(FILE *, u_int8_t *);
00469 void parse_interface_declaration(FILE *, struct client_config *);
00470 struct interface_info *interface_or_dummy(char *);
00471 void make_client_state(struct interface_info *);
00472 void make_client_config(struct interface_info *, struct client_config *);
00473 void parse_client_lease_statement(FILE *, int);
00474 void parse_client_lease_declaration(FILE *, struct client_lease *,
00475     struct interface_info **);
00476 struct dhcp_option *parse_option_decl(FILE *, struct option_data *);
00477 void parse_string_list(FILE *, struct string_list **, int);
00478 void parse_reject_statement(FILE *, struct client_config *);
00479 
00480 /* privsep.c */
00481 struct buf  *buf_open(size_t);
00482 int      buf_add(struct buf *, void *, size_t);
00483 int      buf_close(int, struct buf *);
00484 ssize_t      buf_read(int, void *, size_t);
00485 void         dispatch_imsg(int);

Generated on Sun May 27 2012 04:23:30 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.