[Dhcp-agent-commits] dhcp-agent dhcp-net.h,NONE,1.1 dhcp-agent.h,1.60,1.61 dhcp-arp-discovery.c,1.5,
Status: Alpha
Brought to you by:
actmodern
From: <act...@us...> - 2002-06-22 01:48:00
|
Update of /cvsroot/dhcp-agent/dhcp-agent In directory usw-pr-cvs1:/tmp/cvs-serv8595 Modified Files: dhcp-agent.h dhcp-arp-discovery.c dhcp-client-control.c dhcp-client-states.c dhcp-icmp-discovery.c dhcp-interface.c dhcp-net.c dhcp-packet-build.c dhcp-sniff.c dhcp-sysconf.c dhcp-util.c dhcp-util.h Added Files: dhcp-net.h Log Message: fixed up previous additions; moved rawnet into its own header file; some bsd fixes but we're still waiting on libdnet response to bugreport --- NEW FILE: dhcp-net.h --- /* $Header: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.h,v 1.1 2002/06/22 01:47:57 actmodern Exp $ * * Copyright 2002 Thamer Alharbash * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * 3. The names of the authors may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * */ #ifndef DHCP_NET_H #define DHCP_NET_H /* Raw net types for packets. */ #define RAWNET_UNKNOWN 0 #define RAWNET_ARP 1 #define RAWNET_ICMP 2 #define RAWNET_DHCP 3 /* Raw net return types when * receiving packets. */ #define RAWNET_OK 0 #define RAWNET_PCAP_ERROR -1 #define RAWNET_MALFORMED_PACKET -2 #define RAWNET_UNHANDLED -3 #define RAWNET_TIMEOUT -4 /* Net/Rawnet routines. */ extern rawnet_t *rawnet_create(char *device, char *filter, int sport, int dport, int promiscuous); extern void rawnet_destroy(rawnet_t *net); extern int rawnet_get_packet(rawnet_t *net); extern int rawnet_get_hw_addr(rawnet_t *net, eth_addr_t *addr); extern int rawnet_get_real_hw_addr(rawnet_t *net, eth_addr_t *addr); extern int rawnet_get_ip_addr(rawnet_t *net, ip_addr_t *addr); extern char *rawnet_strerror(rawnet_t *net); extern int rawnet_send_packet(rawnet_t *net); extern void rawnet_use_fake_hw_addr(rawnet_t *raw, char *mac_string); extern void reinitialize_rawnet(rawnet_t *net, int promiscuous); extern int rawnet_up(rawnet_t *net); extern void rawnet_down(rawnet_t *net); extern int rawnet_packet_transact(rawnet_t *net, void *arg, void (*update)(void *arg), int (*check)(void *arg)); extern int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu); extern int rawnet_interface_down(rawnet_t *net); extern void rawnet_dhcp_update(rawnet_t *net, time_t seconds); extern int rawnet_wait(rawnet_t *net, struct timeval *tm); extern int rawnet_is_dhcp_offer(rawnet_t *net); extern int rawnet_is_valid(rawnet_t *net); #endif Index: dhcp-agent.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-agent.h,v retrieving revision 1.60 retrieving revision 1.61 diff -C2 -d -r1.60 -r1.61 *** dhcp-agent.h 18 Jun 2002 04:33:40 -0000 1.60 --- dhcp-agent.h 22 Jun 2002 01:47:57 -0000 1.61 *************** *** 266,270 **** typedef struct { intf_t *interface_handle; ! struct intf_entry interface_entry; } interface_control_t; --- 266,270 ---- typedef struct { intf_t *interface_handle; ! struct intf_entry *interface_entry; } interface_control_t; *************** *** 434,452 **** # define NETBIOS_H_NODE 0x06 - /* Raw net type. */ - - #define RAWNET_UNKNOWN 0 - #define RAWNET_ARP 1 - #define RAWNET_ICMP 2 - #define RAWNET_DHCP 3 - - /* Raw net return types. */ - - #define RAWNET_OK 0 - #define RAWNET_PCAP_ERROR -1 - #define RAWNET_MALFORMED_PACKET -2 - #define RAWNET_UNHANDLED -3 - #define RAWNET_TIMEOUT -4 - /* DHCP states * We use these internally --- 434,437 ---- *************** *** 492,510 **** extern void cache_entry_purge_list(list_t *cache_list); ! /* Net/Rawnet routines. */ ! ! extern int port_for_service(const char *serv, const char *proto); ! extern int resolv(char *address, uint32_t *addr); ! ! extern rawnet_t *rawnet_create(char *device, char *filter, int sport, int dport, int promiscuous); ! extern void rawnet_destroy(rawnet_t *net); ! extern int rawnet_get_packet(rawnet_t *net); ! extern int rawnet_get_hw_addr(rawnet_t *net, eth_addr_t *addr); ! extern int rawnet_get_real_hw_addr(rawnet_t *net, eth_addr_t *addr); ! extern int rawnet_get_ip_addr(rawnet_t *net, ip_addr_t *addr); ! extern char *rawnet_strerror(rawnet_t *net); ! extern int rawnet_send_packet(rawnet_t *net); ! extern void rawnet_use_fake_hw_addr(rawnet_t *raw, char *mac_string); ! extern void reinitialize_rawnet(rawnet_t *net, int promiscuous); extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); --- 477,481 ---- extern void cache_entry_purge_list(list_t *cache_list); ! /* packet building routines. */ extern void build_dhcp_discover(rawnet_t *net, uint32_t xid, time_t secs, list_t *options); *************** *** 526,535 **** extern void build_unarp(rawnet_t *net, uint32_t source_addr, eth_addr_t source_hw_addr); - - extern void rawnet_dhcp_update(rawnet_t *net, time_t seconds); - extern int rawnet_wait(rawnet_t *net, struct timeval *tm); - extern int rawnet_is_dhcp_offer(rawnet_t *net); - extern int rawnet_is_valid(rawnet_t *net); - extern void build_icmp_mask_request(rawnet_t *net, uint32_t id, uint32_t seq); extern void build_icmp_mask_reply(rawnet_t *net, uint32_t id, uint32_t seq, uint32_t subnet_mask); --- 497,500 ---- *************** *** 537,550 **** eth_addr_t source_mac, eth_addr_t dest_mac, uint32_t id, uint32_t seq); - - extern int rawnet_up(rawnet_t *net); - extern void rawnet_down(rawnet_t *net); - - extern int rawnet_packet_transact(rawnet_t *net, void *arg, - void (*update)(void *arg), - int (*check)(void *arg)); - - extern int rawnet_interface_up(rawnet_t *net, ip_addr_t addr, ip_addr_t netmask, int mtu); - extern int rawnet_interface_down(rawnet_t *net); /* ICMP discovery routines. */ --- 502,505 ---- Index: dhcp-arp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-arp-discovery.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-arp-discovery.c 17 Jun 2002 13:23:07 -0000 1.5 --- dhcp-arp-discovery.c 22 Jun 2002 01:47:57 -0000 1.6 *************** *** 25,28 **** --- 25,29 ---- #include <dhcp-agent.h> #include <dhcp-util.h> + #include <dhcp-net.h> /* Accept a list of arguments. Will contain rawnet first, and Index: dhcp-client-control.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-control.c,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** dhcp-client-control.c 17 Jun 2002 13:23:07 -0000 1.21 --- dhcp-client-control.c 22 Jun 2002 01:47:57 -0000 1.22 *************** *** 25,28 **** --- 25,29 ---- #include <dhcp-util.h> #include <dhcp-globconf.h> + #include <dhcp-net.h> /* Utility routines to update counters and time stamps. */ Index: dhcp-client-states.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-client-states.c,v retrieving revision 1.30 retrieving revision 1.31 diff -C2 -d -r1.30 -r1.31 *** dhcp-client-states.c 19 Jun 2002 01:35:46 -0000 1.30 --- dhcp-client-states.c 22 Jun 2002 01:47:57 -0000 1.31 *************** *** 30,33 **** --- 30,34 ---- #include <dhcp-sysconf.h> #include <dhcp-globconf.h> + #include <dhcp-net.h> /* Along with the parameter request list we always build these options Index: dhcp-icmp-discovery.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-icmp-discovery.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** dhcp-icmp-discovery.c 17 Jun 2002 13:23:08 -0000 1.15 --- dhcp-icmp-discovery.c 22 Jun 2002 01:47:57 -0000 1.16 *************** *** 31,34 **** --- 31,35 ---- #include <dhcp-globconf.h> #include <dhcp-convert.h> + #include <dhcp-net.h> /* Check for icmp mask response. */ Index: dhcp-interface.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-interface.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-interface.c 17 Jun 2002 13:23:08 -0000 1.18 --- dhcp-interface.c 22 Jun 2002 01:47:57 -0000 1.19 *************** *** 30,38 **** /* Internal utilities */ static int interface_get_info(interface_control_t *ic) { ! if(intf_get(ic->interface_handle, &ic->interface_entry) < 0) { ! error_message("interface_control: could not lookup interface %s : %d", ic->interface_entry.intf_name, strerror(errno)); return -1; --- 30,39 ---- /* Internal utilities */ + /* get interface info. */ static int interface_get_info(interface_control_t *ic) { ! if(intf_get(ic->interface_handle, ic->interface_entry) < 0) { ! error_message("interface_control: could not lookup interface %s : %s", ic->interface_entry->intf_name, strerror(errno)); return -1; *************** *** 42,49 **** } static int interface_set_info(interface_control_t *ic) { ! if(intf_set(ic->interface_handle, &ic->interface_entry) < 0) { ! error_message("interface_control: could not lookup interface %s : %d", ic->interface_entry.intf_name, strerror(errno)); return -1; --- 43,51 ---- } + /* set interface info. */ static int interface_set_info(interface_control_t *ic) { ! if(intf_set(ic->interface_handle, ic->interface_entry) < 0) { ! error_message("interface_control: could not lookup interface %s : %s", ic->interface_entry->intf_name, strerror(errno)); return -1; *************** *** 57,60 **** --- 59,63 ---- { interface_control_t *ic; + void *buf; ic = xcalloc(sizeof(interface_control_t)); *************** *** 64,69 **** fatal_error("interface_control: could not acquire interface handler"); ! strncpy(ic->interface_entry.intf_name, name, sizeof(ic->interface_entry.intf_name) -1); ! ic->interface_entry.intf_name[sizeof(ic->interface_entry.intf_name) -1] = 0; return ic; --- 67,74 ---- fatal_error("interface_control: could not acquire interface handler"); ! buf = xcalloc(1024); ! ic->interface_entry = buf; ! strncpy(ic->interface_entry->intf_name, name, sizeof(ic->interface_entry->intf_name) -1); ! ic->interface_entry->intf_name[sizeof(ic->interface_entry->intf_name) -1] = 0; return ic; *************** *** 73,76 **** --- 78,82 ---- { intf_close(ic->interface_handle); + xfree(ic->interface_entry); xfree(ic); } *************** *** 83,87 **** return -1; ! return(ic->interface_entry.intf_flags&INTF_FLAG_UP); } --- 89,93 ---- return -1; ! return(ic->interface_entry->intf_flags&INTF_FLAG_UP); } *************** *** 94,103 **** /* Set address if needed. */ ! ! if(addr != INADDR_ANY) { ! ic->interface_entry.intf_addr.addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, ! &ic->interface_entry.intf_addr.addr_bits); ! memcpy(&ic->interface_entry.intf_addr.addr_ip, &addr, IP_ADDR_LEN); } --- 100,109 ---- /* Set address if needed. */ ! ! if(addr != 0) { ! ic->interface_entry->intf_addr.addr_type = ADDR_TYPE_IP; ! addr_mtob(&netmask, IP_ADDR_LEN, ! &ic->interface_entry->intf_addr.addr_bits); ! memcpy(&ic->interface_entry->intf_addr.addr_ip, &addr, IP_ADDR_LEN); } *************** *** 105,113 **** if(mtu != -1) ! ic->interface_entry.intf_mtu = mtu; else ! ic->interface_entry.intf_mtu = DEFAULT_MTU; ! ic->interface_entry.intf_flags |= INTF_FLAG_UP; if(interface_set_info(ic)) --- 111,119 ---- if(mtu != -1) ! ic->interface_entry->intf_mtu = mtu; else ! ic->interface_entry->intf_mtu = DEFAULT_MTU; ! ic->interface_entry->intf_flags |= INTF_FLAG_UP; if(interface_set_info(ic)) *************** *** 124,128 **** return -1; ! ic->interface_entry.intf_flags &= ~INTF_FLAG_UP; if(interface_set_info(ic)) --- 130,134 ---- return -1; ! ic->interface_entry->intf_flags &= ~INTF_FLAG_UP; if(interface_set_info(ic)) *************** *** 138,142 **** return -1; ! memcpy(addr, &ic->interface_entry.intf_addr.addr_ip, IP_ADDR_LEN); return 0; --- 144,148 ---- return -1; ! memcpy(addr, &ic->interface_entry->intf_addr.addr_ip, IP_ADDR_LEN); return 0; *************** *** 235,236 **** --- 241,243 ---- return(interfaces_get_proc(check_interface_down)); } + Index: dhcp-net.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-net.c,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** dhcp-net.c 17 Jun 2002 13:23:08 -0000 1.27 --- dhcp-net.c 22 Jun 2002 01:47:57 -0000 1.28 *************** *** 51,61 **** * to set the destination ethernet header * accordingly. ! * ! * Currently we implement these features by ! * using libpcap for receiving packets, ! * and libdnet for sending them. ! * * The only limitation here is that we can only ! * do DHCP over ethernet which is fine. * */ --- 51,57 ---- * to set the destination ethernet header * accordingly. ! * * The only limitation here is that we can only ! * do DHCP over ethernet which is fine -- for now. * */ *************** *** 64,109 **** #include <dhcp-util.h> #include <dhcp-rtt.h> ! ! /* Get port number for named service. */ ! ! int port_for_service(const char *serv, const char *proto) ! { ! struct servent *sv; ! ! setservent(0); ! ! if((sv = getservbyname(serv, proto)) == NULL) { ! error_message("rawnet: could not get service listing: %d", strerror(errno)); ! return -1; ! } ! ! return(sv->s_port); ! } ! ! /* Returns 0 on success or -1 if error. ! * Fills in addr with 32-bit ipv4 address */ ! ! extern int h_errno; ! ! int resolv(char *address, uint32_t *addr) ! { ! struct hostent *host; ! ! *(addr) = inet_addr(address); ! ! if(*(addr) == INADDR_NONE) { ! ! host = gethostbyname(address); ! ! if(host == NULL) { ! error_message("rawnet: unable to resolv host: %s", hstrerror(h_errno)); ! return -1; ! } ! ! memcpy(&addr, (int *) * &host->h_addr, sizeof(addr)); ! } ! ! return 0; ! } /* get interface address. */ --- 60,64 ---- #include <dhcp-util.h> #include <dhcp-rtt.h> ! #include <dhcp-net.h> /* get interface address. */ *************** *** 228,241 **** net->promiscuous = promiscuous; - /* Get the interface and make sure its an ethernet interface or - * else we're hosed. */ - - net->eth = eth_open(device); - if(net->eth == NULL) { - error_message("rawnet: device not supported or unavailable: %s", device); - rawnet_destroy(net); - return NULL; - } - /* get the interface handle for bringing it up or down and querying it. */ net->intf_handle = create_interface_control(net->device); --- 183,186 ---- *************** *** 246,254 **** /* Is the interface up? */ ! if(!interface_is_up(net->intf_handle)) ! rawnet_interface_up(net, 0, 0xffffff, -1); /* then bring it up with dum values. */ ! /* get pcap handler */ net->pcap = initialize_pcap_device(device, filter, promiscuous); if(net->pcap == NULL) { --- 191,213 ---- /* Is the interface up? */ ! if(!interface_is_up(net->intf_handle)) { ! /* then bring it up with dum values. */ ! if(rawnet_interface_up(net, 0, 0xffffff, -1)) { ! rawnet_destroy(net); ! return NULL; ! } ! } ! /* Get the interface and make sure its an ethernet interface or ! * else we're hosed. */ ! ! net->eth = eth_open(device); ! if(net->eth == NULL) { ! error_message("rawnet: device not supported or unavailable: %s: %s", device, strerror(errno)); ! rawnet_destroy(net); ! return NULL; ! } + /* get pcap handler */ net->pcap = initialize_pcap_device(device, filter, promiscuous); if(net->pcap == NULL) { *************** *** 259,263 **** net->pcap_fd = pcap_fileno(net->pcap); if(net->pcap_fd < 0) { ! error_message("rawnet: cannot get descriptor for %s, this system may not be supported.", device); rawnet_destroy(net); return NULL; --- 218,222 ---- net->pcap_fd = pcap_fileno(net->pcap); if(net->pcap_fd < 0) { ! error_message("rawnet: cannot get descriptor for %s, this system may is not supported.", device); rawnet_destroy(net); return NULL; *************** *** 271,275 **** rawnet_get_ip_addr(net, &net->ip_addr); ! /* Build packet handler objects. * * These exit on failure. --- 230,234 ---- rawnet_get_ip_addr(net, &net->ip_addr); ! /* Packet handler objects. * * These exit on failure. *************** *** 312,318 **** eth_close(net->eth); ! if(net->intf_handle) { destroy_interface_control(net->intf_handle); - } if(net->pcap != NULL) --- 271,276 ---- eth_close(net->eth); ! if(net->intf_handle) destroy_interface_control(net->intf_handle); if(net->pcap != NULL) Index: dhcp-packet-build.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-packet-build.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-packet-build.c 17 Jun 2002 13:23:08 -0000 1.5 --- dhcp-packet-build.c 22 Jun 2002 01:47:57 -0000 1.6 *************** *** 28,31 **** --- 28,32 ---- #include <dhcp-agent.h> #include <dhcp-util.h> + #include <dhcp-net.h> /* constants we need. */ Index: dhcp-sniff.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sniff.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** dhcp-sniff.c 18 Jun 2002 04:33:40 -0000 1.10 --- dhcp-sniff.c 22 Jun 2002 01:47:57 -0000 1.11 *************** *** 28,31 **** --- 28,32 ---- #include <dhcp-util.h> #include <dhcp-print.h> + #include <dhcp-net.h> int interactive = 1; Index: dhcp-sysconf.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-sysconf.c,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** dhcp-sysconf.c 17 Jun 2002 13:23:08 -0000 1.19 --- dhcp-sysconf.c 22 Jun 2002 01:47:57 -0000 1.20 *************** *** 30,33 **** --- 30,34 ---- #include <dhcp-convert.h> #include <dhcp-sysconf.h> + #include <dhcp-net.h> /* Only use handlers here which can be done in any order. *************** *** 213,217 **** info_message("configuring interface: %s", dc->interface); ! for(list_ptr = options;list_ptr;list_ptr = list_ptr->next) { --- 214,218 ---- info_message("configuring interface: %s", dc->interface); ! for(list_ptr = options;list_ptr;list_ptr = list_ptr->next) { *************** *** 249,253 **** if(!have_addr && !have_netmask) fatal_error("do not have enough settings for interface configuration!"); - if(rawnet_interface_up(dc->rawnet, addr, netmask, mtu)) fatal_error("could not bring up interface: %s", dc->interface); --- 250,253 ---- *************** *** 273,277 **** /* we need to setup the interface ourselves before * anything (route won't work otherwise.) */ - for(list_ptr = options;list_ptr;list_ptr = list_ptr->next) { --- 273,276 ---- Index: dhcp-util.c =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** dhcp-util.c 19 Jun 2002 00:57:16 -0000 1.18 --- dhcp-util.c 22 Jun 2002 01:47:57 -0000 1.19 *************** *** 591,592 **** --- 591,634 ---- return have_io; } + + /* Get port number for named service. */ + + int port_for_service(const char *serv, const char *proto) + { + struct servent *sv; + + setservent(0); + + if((sv = getservbyname(serv, proto)) == NULL) { + error_message("rawnet: could not get service listing: %d", strerror(errno)); + return -1; + } + + return(sv->s_port); + } + + /* Returns 0 on success or -1 if error. + * Fills in addr with 32-bit ipv4 address */ + + extern int h_errno; + + int resolv(char *address, uint32_t *addr) + { + struct hostent *host; + + *(addr) = inet_addr(address); + + if(*(addr) == INADDR_NONE) { + + host = gethostbyname(address); + + if(host == NULL) { + error_message("rawnet: unable to resolv host: %s", hstrerror(h_errno)); + return -1; + } + + memcpy(&addr, (int *) * &host->h_addr, sizeof(addr)); + } + + return 0; + } Index: dhcp-util.h =================================================================== RCS file: /cvsroot/dhcp-agent/dhcp-agent/dhcp-util.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** dhcp-util.h 19 Jun 2002 00:57:16 -0000 1.5 --- dhcp-util.h 22 Jun 2002 01:47:57 -0000 1.6 *************** *** 66,69 **** --- 66,71 ---- extern void track_sigio(void); extern int had_io(void); + extern int resolv(char *address, uint32_t *addr); + extern int port_for_service(const char *serv, const char *proto); #endif /* DHCP_UTIL_H */ |