Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

packets_operations.c File Reference

#include "server_config.h"
#include "packets_operations.h"
#include "dhcp.h"

Go to the source code of this file.

Functions

void clear_profile (struct opt *options)
 Reset option profile to "all zeros". More...

int add_option_to_profile (struct opt *mprofile, int option, char *type, char *value, int len)
 Add an option to the loaded profile. More...

int remove_option_from_profile (struct opt *mprofile, int option)
 Remove an option from the loaded profile. More...

void context2profile (struct opt *profile, struct mysql_tables *mysql_tables)
 Copy the options' profile extracted from the client's context into a 'opt' data structure (used to assemble the output DHCP packet). More...

int packets_send_offer (struct dhcp_packet *p, struct mysql_tables *mysql_tables, char *ip, unsigned long int broadcast, unsigned long int server_ip, int socket_desc, struct sockaddr_in *client_address, int tip)
 Send a DHCPOFFER and log the output packet. More...

int packets_send_ack (struct dhcp_packet *p, struct mysql_tables *mysql_tables, char *ip, unsigned long int broadcast, unsigned long int server_ip, int socket_desc, struct sockaddr_in *client_address, int tip)
 Send a DHCPACK in response to a REQUEST and log the output packet. More...

int log_profile (const char *file, const char *mes, const struct opt *profile)
 Log a packet's profile (list of options) in a human readables format. More...

int reply_to_inform (struct dhcp_packet *p, struct mysql_tables *mysql_tables, unsigned long int broadcast, unsigned long int server_ip, int socket_desc, struct sockaddr_in *client_address)
 Send a DHCPACK as response to an INFORM. More...

int packets_send_nack (struct dhcp_packet *p, struct mysql_tables *mysql_tables, char *ip, unsigned long int broadcast, unsigned long int server_ip, int socket_desc, struct sockaddr_in *client_address)
 Send a DHCPNAK in response to a REQUEST and log the output packet. More...

int packets_send_dummy_nak (struct dhcp_packet *p, struct mysql_tables *mysql_tables, char *ip, unsigned long int broadcast, unsigned long int server_ip, int socket_desc, struct sockaddr_in *client_address)
 Send a dummy DHCPNAK and log the output packet. More...


Variables

global_config configuration_globale
 Global DHCP configuration handler.


Detailed Description

This file implements output packet mechanism (OFFER, ACK or INFORM).

Definition in file packets_operations.c.


Function Documentation

int add_option_to_profile struct opt   mprofile,
int    option,
char *    type,
char *    value,
int    len
[static]
 

Add an option to the loaded profile.

Author:
Denis BEURIVE
Parameters:
mprofile  Pointer to an array of 'opt' data structures that represents the profile to manipulate.
option  Option's code (between 1 and 254 included).
type  Pointer to a zero terminated string of characters the represents the type of value. Type could be:
  • "UINT32" (values are separated by ':')
  • "UINT16" (values are separated by ':')
  • "IP" (values are separated by ':')
  • "HEXA-BYTE"
  • "ASCII-BYTE"
value  Pointer to the value. The format of the value depends on its type.
len  Number of bytes of the value.
Returns:
Upon successful completion, the function returns the value 0. Otherwize, the function returns the value 1.

Definition at line 64 of file packets_operations.c.

References ascii_to_binary(), hexa_to_binary(), ip_to_network_byte_order(), global_config::log_file, my_syslog(), uint16_to_network_byte_order(), uint32_to_network_byte_order(), and VALUE_MAX_SIZE.

Referenced by packets_send_ack(), packets_send_nack(), packets_send_offer(), and reply_to_inform().

void clear_profile struct opt   options [static]
 

Reset option profile to "all zeros".

Author:
Denis BEURIVE
Parameters:
options  Pointer to a destination 'opt' data structure to reset.
Warning:
The pointer 'options' should point to an array which contains at least MAX_PROFILE_OPTIONS (which should be greater than 256) elements.

Definition at line 33 of file packets_operations.c.

References opt::code, opt::len, MAX_PROFILE_OPTIONS, and VALUE_MAX_SIZE.

Referenced by context2profile(), and packets_send_nack().

void context2profile struct opt   profile,
struct mysql_tables   mysql_tables
[static]
 

Copy the options' profile extracted from the client's context into a 'opt' data structure (used to assemble the output DHCP packet).

Author:
Denis BEURIVE
Parameters:
profile  Pointer to a destination 'opt' data structure.
mysql_tables  Pointer to a 'mysql_tables' data structure that contains the client's context (loaded form the database).
Remarks:
Types of options' values can be:
  • "UINT32" (one or more values, separated by ':')
  • "UINT16" (one or more values, separated by ':')
  • "IP" (one or more values, separated by ':')
  • "HEXA-BYTE"
  • "ASCII-BYTE"
Warning:
The pointer 'options' should point to an array which contains at least MAX_PROFILE_OPTIONS (which should be greater than 256) elements.

Definition at line 183 of file packets_operations.c.

References ascii_to_binary(), clear_profile(), hexa_to_binary(), ip_to_network_byte_order(), global_config::log_file, my_syslog(), mysql_tables::option_number, mysql_tables::options, uint16_to_network_byte_order(), uint32_to_network_byte_order(), and VALUE_MAX_SIZE.

Referenced by packets_send_ack(), packets_send_offer(), and reply_to_inform().

int log_profile const char *    file,
const char *    mes,
const struct opt   profile
 

Log a packet's profile (list of options) in a human readables format.

Author:
Denis BEURIVE
Parameters:
file  Pointer to a zero terminated string of characters that represents the path to the log file.
mes  Pointer to a zero terminated string of characters that represents a text that will be printed before the profile.
profile  pointer to a opt data structure that contains the profile to print.
Returns:
Upon successful completion, the function returns the value 0. Othrwise, the function returns the value 1.

Definition at line 719 of file packets_operations.c.

References dater().

int packets_send_ack struct dhcp_packet   p,
struct mysql_tables   mysql_tables,
char *    ip,
unsigned long int    broadcast,
unsigned long int    server_ip,
int    socket_desc,
struct sockaddr_in *    client_address,
int    tip
 

Send a DHCPACK in response to a REQUEST and log the output packet.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the incoming packet (should be a DHCP REQUEST).
mysql_tables  pointer to a 'mysql_tables' data structure that contains the loaded client's context.
ip  Pointer to a zero terminated string of characters that represents the client's IP address.
broadcast  4 bytes long integer that contains the binary representation (in network byte order) of the broadcast IP address.
server_ip  4 bytes long integer that contains the binary representation (in network byte order) of the server IP address.
socket_desc  Socket descriptor of the DHCP server.
client_address  Pointer to a 'sockaddr_in' data structure that contains the internet address of the incoming packet's sender. If the configuration tag 'enable-broadcast-responses' is set to "yes", then the parameter 'client_address' is never used (since the server always sends broadcasts).
tip  Flag that indicates wether the IP address should be taken from the STATIC pool or the dynamic pool. Values can be:
Returns:
Upon successful completion, the function returns the value 0. Otherwise, the function returns the value 1.

Definition at line 520 of file packets_operations.c.

References mysql_tables::abonne_ip, add_option_to_profile(), BOOTREPLY, global_config::broadcast_mode, context2profile(), global_config::csv_file, dhcp_packet::ctrl, global_config::debug, global_config::debug_file, DHCPACK_HEXA, global_config::dumper_mode, DYNAMIC_IP, table_abonne_ip::gateway, table_ip_lease::gateway, mysql_tables::ip_lease, global_config::log_file, my_syslog(), packet_dump(), packets_clear(), packets_close_option(), packets_get_bin_chaddr(), packets_get_bin_ciaddr(), packets_get_bin_giaddr(), packets_get_flags(), packets_get_hlen(), packets_get_htype(), packets_get_secs(), packets_get_xid(), packets_set_bin_ciaddr(), packets_set_bin_giaddr(), packets_set_chaddr(), packets_set_flags(), packets_set_hlen(), packets_set_hops(), packets_set_htype(), packets_set_op(), packets_set_option(), packets_set_secs(), packets_set_siaddr(), packets_set_xid(), packets_set_yiaddr(), global_config::server_ip_seen_by_client, STATIC_IP, table_abonne_ip::subnet, table_ip_lease::subnet, op_control::taille, and TARGET_PORT.

Referenced by find_ip_and_reply().

int packets_send_dummy_nak struct dhcp_packet   p,
struct mysql_tables   mysql_tables,
char *    ip,
unsigned long int    broadcast,
unsigned long int    server_ip,
int    socket_desc,
struct sockaddr_in *    client_address
 

Send a dummy DHCPNAK and log the output packet.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the incoming packet (should be a DHCP REQUEST).
mysql_tables  pointer to a 'mysql_tables' data structure that contains the loaded client's context.
ip  Pointer to a zero terminated string of characters that represents the client's IP address.
broadcast  4 bytes long integer that contains the binary representation (in network byte order) of the broadcast IP address.
server_ip  4 bytes long integer that contains the binary representation (in network byte order) of the server IP address.
socket_desc  Socket descriptor of the DHCP server.
client_address  Pointer to a 'sockaddr_in' data structure that contains the internet address of the incoming packet's sender. If the configuration tag 'enable-broadcast-responses' is set to "yes", then the parameter 'client_address' is never used (since the server always sends broadcasts).
Returns:
Upon successful completion, the function returns the value 0. Otherwise, the function returns the value 1.

Definition at line 1084 of file packets_operations.c.

References global_config::log_file, my_syslog(), and packets_send_nack().

Referenced by main().

int packets_send_nack struct dhcp_packet   p,
struct mysql_tables   mysql_tables,
char *    ip,
unsigned long int    broadcast,
unsigned long int    server_ip,
int    socket_desc,
struct sockaddr_in *    client_address
 

Send a DHCPNAK in response to a REQUEST and log the output packet.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the incoming packet (should be a DHCP REQUEST).
mysql_tables  pointer to a 'mysql_tables' data structure that contains the loaded client's context.
ip  Pointer to a zero terminated string of characters that represents the client's IP address.
broadcast  4 bytes long integer that contains the binary representation (in network byte order) of the broadcast IP address.
server_ip  4 bytes long integer that contains the binary representation (in network byte order) of the server IP address.
socket_desc  Socket descriptor of the DHCP server.
client_address  Pointer to a 'sockaddr_in' data structure that contains the internet address of the incoming packet's sender. If the configuration tag 'enable-broadcast-responses' is set to "yes", then the parameter 'client_address' is never used (since the server always sends broadcasts).
Returns:
Upon successful completion, the function returns the value 0. Otherwise, the function returns the value 1.

Definition at line 921 of file packets_operations.c.

References add_option_to_profile(), BOOTREPLY, global_config::broadcast_mode, clear_profile(), global_config::csv_file, dhcp_packet::ctrl, global_config::debug, global_config::debug_file, DHCPNAK_HEXA, global_config::dumper_mode, global_config::log_file, my_syslog(), packet_dump(), packets_clear(), packets_close_option(), packets_get_bin_chaddr(), packets_get_bin_ciaddr(), packets_get_bin_giaddr(), packets_get_flags(), packets_get_hlen(), packets_get_htype(), packets_get_secs(), packets_get_xid(), packets_set_bin_ciaddr(), packets_set_bin_giaddr(), packets_set_chaddr(), packets_set_flags(), packets_set_hlen(), packets_set_hops(), packets_set_htype(), packets_set_op(), packets_set_option(), packets_set_secs(), packets_set_siaddr(), packets_set_xid(), packets_set_yiaddr(), global_config::server_ip_seen_by_client, op_control::taille, and TARGET_PORT.

Referenced by find_ip_and_reply(), and packets_send_dummy_nak().

int packets_send_offer struct dhcp_packet   p,
struct mysql_tables   mysql_tables,
char *    ip,
unsigned long int    broadcast,
unsigned long int    server_ip,
int    socket_desc,
struct sockaddr_in *    client_address,
int    tip
 

Send a DHCPOFFER and log the output packet.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the incoming packet (should be a DHCP DISCOVER).
mysql_tables  pointer to a 'mysql_tables' data structure that contains the loaded client's context.
ip  Pointer to a zero terminated string of characters that represents the IP address of the user.
broadcast  4 bytes long integer that contains the binary representation (in network byte order) of the broadcast IP address.
server_ip  4 bytes long integer that contains the binary representation (in network byte order) of the server IP address.
socket_desc  Socket descriptor of the DHCP server.
client_address  Pointer to a 'sockaddr_in' data structure that contains the internet address of the incoming packet's sender. If the configuration tag 'enable-broadcast-responses' is set to "yes", then the parameter 'client_address' is never used (since the server always send broadcasts).
tip  Flag that indicates wether the IP address should be taken from the STATIC pool or the dynamic pool. Values can be:
Returns:
Upon successful completion, the function returns the value 0. Otherwise, the function returns the value 1.

Definition at line 309 of file packets_operations.c.

References mysql_tables::abonne_ip, add_option_to_profile(), BOOTREPLY, global_config::broadcast_mode, context2profile(), global_config::csv_file, dhcp_packet::ctrl, global_config::debug, global_config::debug_file, DHCPOFFER_HEXA, global_config::dumper_mode, DYNAMIC_IP, table_abonne_ip::gateway, table_ip_lease::gateway, mysql_tables::ip_lease, global_config::log_file, my_syslog(), packet_dump(), packets_clear(), packets_close_option(), packets_get_bin_chaddr(), packets_get_bin_giaddr(), packets_get_flags(), packets_get_hlen(), packets_get_htype(), packets_get_secs(), packets_get_xid(), packets_set_bin_giaddr(), packets_set_chaddr(), packets_set_flags(), packets_set_hlen(), packets_set_hops(), packets_set_htype(), packets_set_op(), packets_set_option(), packets_set_secs(), packets_set_siaddr(), packets_set_xid(), packets_set_yiaddr(), global_config::server_ip_seen_by_client, STATIC_IP, table_abonne_ip::subnet, table_ip_lease::subnet, op_control::taille, and TARGET_PORT.

Referenced by find_ip_and_reply().

int remove_option_from_profile struct opt   mprofile,
int    option
[static]
 

Remove an option from the loaded profile.

Author:
Denis BEURIVE
Parameters:
mprofile  Pointer to an array of 'opt' data structures that represents the profile to manipulate.
option  Option's code (between 1 and 254 included).
Returns:
Upon successful completion, the function returns the value 0. Otherwize, the function returns the value 1.

Definition at line 146 of file packets_operations.c.

References global_config::log_file, my_syslog(), and VALUE_MAX_SIZE.

Referenced by reply_to_inform().

int reply_to_inform struct dhcp_packet   p,
struct mysql_tables   mysql_tables,
unsigned long int    broadcast,
unsigned long int    server_ip,
int    socket_desc,
struct sockaddr_in *    client_address
 

Send a DHCPACK as response to an INFORM.

Author:
Denis BEURIVE
Parameters:
p  Pointer to the incoming packet (should be a DHCP INFORM).
mysql_tables  pointer to a 'mysql_tables' data structure that contains the loaded client's context.
broadcast  4 bytes long integer that contains the binary representation (in network byte order) of the broadcast IP address.
server_ip  4 bytes long integer that contains the binary representation (in network byte order) of the server IP address.
socket_desc  Socket descriptor of the DHCP server.
client_address  Pointer to a 'sockaddr_in' data structure that contains the internet address of the incoming packet's sender. If the configuration tag 'enable-broadcast-responses' is set to "yes", then the parameter 'client_address' is never used (since the server always send broadcasts).
Returns:
Upon successful completion, the function returns the value 0. Otherwise, the function returns the value 1.

Definition at line 769 of file packets_operations.c.

References add_option_to_profile(), BOOTREPLY, global_config::broadcast_mode, context2profile(), global_config::csv_file, dhcp_packet::ctrl, global_config::debug, global_config::debug_file, DHCPACK_HEXA, global_config::dumper_mode, global_config::log_file, my_syslog(), packet_dump(), packets_clear(), packets_close_option(), packets_get_bin_chaddr(), packets_get_bin_ciaddr(), packets_get_bin_giaddr(), packets_get_flags(), packets_get_hlen(), packets_get_htype(), packets_get_secs(), packets_get_xid(), packets_set_bin_ciaddr(), packets_set_bin_giaddr(), packets_set_chaddr(), packets_set_flags(), packets_set_hlen(), packets_set_hops(), packets_set_htype(), packets_set_op(), packets_set_option(), packets_set_secs(), packets_set_siaddr(), packets_set_xid(), remove_option_from_profile(), global_config::server_ip_seen_by_client, op_control::taille, and TARGET_PORT.

Referenced by find_ip_and_reply().


Generated on Mon Jun 19 12:31:07 2006 for MyDhcp_V2 by doxygen1.2.15