Annotation of embedaddon/dhcdrop/src/dhcdrop.h, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2009 by Chebotarev Roman <roma@ultranet.ru>
3: *
4: * This program is free software; you can redistribute it and/or modify
5: * it under the terms of the GNU General Public License as published by
6: * the Free Software Foundation; either version 2 of the License.
7: *
8: * This program is distributed in the hope that it will be useful,
9: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU General Public License for more details.
12: *
13: * You should have received a copy of the GNU General Public License
14: * along with this program; if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16: */
17:
18: #ifndef DHCDROP_H
19: #define DHCDROP_H
20:
21: #define RELEASE_DATE "05.08.2009"
22: #define PROG_NAME "DHCP-dropper"
23: #define BASE_VERSION PROG_NAME" v0.5"
24: #define VERSION BASE_VERSION
25:
26: #define COPYRIGHT VERSION" was written by Chebotarev Roman at "RELEASE_DATE"\n"
27: #define HOMEPAGE "Home page: http://www.netpatch.ru/en/dhcdrop.html"
28:
29:
30: /* Function for filling configuration structure 'params' from command line arguments */
31: void configure(const int argc, char **argv, struct config_params * params);
32:
33: /* Execute all programm actions */
34: int exec_action(const struct config_params * config);
35:
36: /* Discover available network interfaces.
37: * If 'num' not zero - return name of interface with index 'num' if success, 0 otherwise. */
38: char * interfaces_discover(const int num);
39:
40: /* Creating and launch children for generate DHCP flood. */
41: void send_flood(const struct config_params * params);
42:
43: /* Get ethernet address of illegal DHCP server in network.
44: * Retrun: 0 if server not found, ILLEGAL_SERV_FOUND if illegal server found. Error code otherwise. */
45: int get_dhcp_server(const struct config_params * config, /* Configuration parametrs. Can't be NULL */
46: pcap_t * pcap_socket, /* Pointer to pcap device. Can't be NULL */
47: struct dhcp_packet_net_header * net_header, /* Can't be NULL */
48: struct dhcp_packet * server_response, /* Function store DHCP response server here, */
49: /* can't be NULL */
50: uint16_t * response_length);
51:
52: /* Drop DHCP server specified in 'srv_etheraddr'. Return number of address recieved. */
53: int drop_dhcp_server(const struct config_params * config, /* Can't be NULL */
54: pcap_t * pcap_socket, /* Pointer to pcap device. Can't be NULL */
55: const char * srv_etheraddr); /* Ethrenet addres of DHCP server to dropping */
56:
57: /* Scanning network for search hosts with invalid IP configuration and send
58: * DHCPRELEASE for each found hosts to illegal DHCP server. Return zero if success, -1 otherwise */
59: int agressive_clean_leases(pcap_t * pcap_socket, /* Pointer to pcap device. Can't be NULL */
60: const struct config_params * config, /* Can't be NULL */
61: struct dhcp_packet_net_header * net_header, /* Network header from DHCP server response */
62: const struct dhcp_packet * srv_resp, /* Pointer to structure contain server DHCPOFFER response */
63: uint16_t resp_len); /* Length DHCPOFFER */
64:
65: /* ARP scan network on interface 'pcap_socket' in range specified by network/netmask. */
66: void scan_subnet(pcap_t * pcap_socket, /* Pointer to pcap device. Can't be NULL */
67: uint32_t from_ip, /* Source IP address. If == 0 - using random value */
68: const uint8_t * from_eth, /* Source ethernet address. */
69: const uint32_t network, /* Destination network */
70: const uint32_t netmask); /* Network mask */
71:
72: /* ARP scan network on interface 'pcap_socket' in IP range 'start_range' - 'end_range'
73: * Return zero if success, error code otherwise. */
74: int arp_scan(pcap_t * pcap_socket, /* Pointer to pcap device. Can't be NULL */
75: const uint32_t start_range, /* Start IP range. Host byte order! */
76: const uint32_t end_range, /* End IP range. Host byte order! */
77: uint32_t from_ip, /* Source IP address */
78: const uint8_t * from_ether); /* Source ethernet address */
79:
80: /* Return 0 if success, or error code otherwise. */
81: int send_arpreq(pcap_t * pcap_socket, /* Pointer to pcap device. Can't be NULL */
82: const uint32_t to_ip, /* Destination of ARP request */
83: const uint32_t from_ip, /* Source IP address */
84: const uint8_t * from_ether); /* Source ethernet address */
85:
86: /* Waiting ARP responses on interface 'pcap_socket' */
87: int get_arpresps(pcap_t * pcap_socket, /* Pointer to pcap device. Can't be NULL */
88: int timeout); /* Timeout in seconds */
89:
90: #ifdef _WIN32
91: /* Keyboard interrupt handler */
92: BOOL WINAPI int_sign(DWORD signal);
93:
94: /* Generate DHCP flood - one thread. Windows version. */
95: unsigned __stdcall start_flood( void* arg );
96:
97: #else
98: /* Keyboard interrupt handler */
99: int int_sign(int32_t signal);
100: /* Generate DHCP flood - one child. UNIX-like version. */
101: int start_flood( void* arg );
102: #endif
103:
104: /* Create new child process (for UNIX) or new thread (for Windows) for generate DHCP flood. */
105: void new_child(const struct flood_params * p, const int child_num);
106:
107: /* Wait unless all child DHCP flood processes (in UNIX)/ threads (in Windows) finished. */
108: void wait_children(const struct flood_params * p);
109:
110: /* Make filter expression for pcap_setfilter() function for discover
111: * DHCP servers in network. Return 0 if success, or error code otherwise. */
112: int make_serverdiscover_filter(char * out_filter, const int max_filter_len,
113: const struct config_params * config, const char * src_etheraddr);
114:
115: /* Make filter expression for pcap_setfilter() function for ARP scanning
116: * network. Return 0 if success, or error code otherwise. */
117: int make_arp_filter(char * out_filter, const int max_filter_len, const char * src_etheraddr);
118:
119: /* Make filter expression for pcap_setfilter() function to drop
120: * DHCP servers specified in 'server_ethaddr'. Using client Ethernet address
121: * specified in 'src_etheraddr'. Return 0 if success, or error code otherwise. */
122: int make_serverdrop_filter(char * out_filter, const int max_filter_len,
123: const struct config_params * config,
124: const char * src_etheraddr, const char * server_ethaddr);
125:
126: /* Set filter specified in 'filter_expression' to interface 'pcap_socket'.
127: * Return 0 if success, or error code otherwise. */
128: int set_pcap_filter(pcap_t * pcap_socket, char * filter_expression);
129:
130: /* Create and send DHCPDISCOVER from pseudo-client 'ether_src'.
131: * Return 0 if success, or error code otherwise. */
132: int send_dhcp_discover(pcap_t * pcap_socket, /* Can't be NULL */
133: const struct config_params * config, /* Can't be NULL */
134: uint8_t * ether_src, /* May be NULL */
135: const uint32_t xid);
136:
137: /* Create and send DHCPDISCOVER from pseudo-client 'ether_src' to DHCP server.
138: * Return 0 if success, or error code otherwise. */
139: int send_dhcp_request(pcap_t * pcap_socket, const struct config_params * config,
140: uint8_t * src_ether, /* Pseudo-client source ethernet address. Can't be NULL */
141: const uint32_t server_ip_address, /* DHCP server IP address. Can't be NULL */
142: const uint32_t req_ip_addr, /* Required client IP address. Can't be NULL */
143: const int32_t xid); /* DHCP transcaction XID */
144:
145: int send_dhcp_release(pcap_t * pcap_socket, const struct config_params * config,
146: const uint8_t * src_ether, /* Pseudo-client source ethernet address. Can't be NULL */
147: const uint32_t server_ip_address, /* DHCP server IP address. Can't be NULL */
148: const uint32_t cl_ip_addr, /* Released client IP address. Can't be NULL */
149: const int32_t xid
150: );
151:
152: /* Waiting DHCP response of type specified in 'resp_type' from server.
153: * Return: -1 if timeout; 0 if DHCP server responded or error code otherwise. */
154: int get_dhcp_response(pcap_t * pcap_socket, /* Can't be NULL */
155: const int timeout, const uint8_t resp_type, /* Timeout in seconds */
156: const uint32_t xid, /* DHCP transcaction XID */
157: struct dhcp_packet_net_header * net_header, /* Function store network header (Ethernet, IP, UDP)
158: here. Can't be NULL */
159: struct dhcp_packet * response, /* Function store DHCP response here. Can't be NULL */
160: int * dhcp_data_len); /* Function store DHCP data length here. Can't be NULL*/
161:
162: /* Function that implements a list of legal DHCP server list. */
163: struct ignored_mac_node * ignor_servers_list(
164: enum list_operations operation, /* Operation type. See enum 'list_operations'
165: in dhcdrop_types.h */
166: char * ether_addr); /* Ethernet address of DHCP server */
167:
168: /* Function that implements a list of legal IP networks on interface */
169: uint32_t legal_nets_list(enum list_operations operation, /* Operation type. See enum 'list_operations'
170: in dhcdrop_types.h */
171: const uint32_t * value); /* Network IP address */
172: /* Function that implements a list of hosts */
173: int hosts_list(enum list_operations operation, /* Operation type. See enum 'list_operations'
174: in dhcdrop_types.h */
175: uint32_t ip_addr, /* Host IP address */
176: uint8_t * ether_addr); /* Host ethernet address */
177:
178: /* Executed on programm finished. */
179: void cleanup(void);
180:
181: /* Misc functions */
182:
183: /* Decode and print DHCP message. Return DHCP message type is success, 0 otherwise. */
184: int decode_dhcp(const struct dhcp_packet * packet, const uint16_t dhcp_data_len);
185:
186: /* Print usage message. Print help message if 'help' != 0 */
187: void usage(const char help);
188:
189: /* Convert network mask to CIDR notation */
190: uint32_t to_cidr(uint32_t mask);
191:
192: /* Convert a numeric IP address to a string */
193: char *iptos(const uint32_t in);
194:
195: /* Print information about network interface */
196: void ifprint(const pcap_if_t *dev);
197:
198: /* Convert ethernet address specified in 'str_addr' to binary format and store to 'bin_addr'.
199: * Return >0 if success. */
200: int etheraddr_str_to_bin(const char * str_addr, uint8_t * bin_addr);
201:
202: /* Convert ethernet address specified in 'bin_addr' to string format and store to 'str_addr'.
203: * Return >0 if success. */
204: inline int etheraddr_bin_to_str(const uint8_t * bin_addr, char * str_addr);
205:
206: /* Replase all '-' symbols in string 'str_ether' to ':' */
207: inline void replace_semicolons(char * str_ether);
208:
209: /* Print ethernet address as hex-digits string */
210: inline void print_ether(const uint8_t * ether_addr);
211:
212: /* Create random ethernet address and store to string 'str_mac_addr' */
213: inline void rand_ether_addr(char * str_mac_addr);
214:
215: #endif /* ifdef DHCDROP_H*/
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>