📄 dhcp-option.c
字号:
/* $Header: /cvsroot/dhcp-agent/dhcp-agent/src/dhcp-option.c,v 1.6 2003/06/27 03:16:27 actmodern Exp $ * * Copyright 2002, 2003 Thamer Alharbash <tmh@whitefang.com> * * 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. * */#define MODULE_NAME "dhcp-option"#include "dhcp-local.h"#include "dhcp-libutil.h"#include "dhcp-librawnet.h"#include "dhcp-option.h"#include "dhcp-option-convert.h"#include "dhcp-limits.h"/* forward declaration of option destructors. */static void dhcp_opt_destroy_string(dhcp_opt_t *opt);static void dhcp_opt_destroy_array(dhcp_opt_t *opt);static void dhcp_opt_destroy_atom(dhcp_opt_t *opt);static void dhcp_opt_destroy_list(dhcp_opt_t *opt);dhcp_opt_attr_t dhcp_opt_attr[] = { /* Pad: we never actually handle this here. so sit all handlers to NULL. */ { TAG_DHCP_PAD, sizeof(uint8_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT8, NULL, NULL, NULL, NULL, NULL, NULL, dhcp_opt_destroy_atom, }, /* Subnet Mask */ { TAG_DHCP_SUBNET_MASK, IP_ADDR_LEN, DHCP_OPT_ATOM, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_ip_addr, dhcp_opt_to_user_string_ip_addr, dhcp_opt_to_internal_string_ip_addr, dhcp_opt_from_network_ip_addr, dhcp_opt_from_user_string_ip_addr, dhcp_opt_from_internal_string_ip_addr, dhcp_opt_destroy_atom, }, /* Time Offset Option */ { TAG_DHCP_TIME_OFFSET, sizeof(int32_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_INT32, dhcp_opt_to_network_int32, dhcp_opt_to_user_string_int32, dhcp_opt_to_internal_string_int32, dhcp_opt_from_network_int32, dhcp_opt_from_user_string_int32, dhcp_opt_from_internal_string_int32, dhcp_opt_destroy_atom, }, /* Router Option */ { TAG_DHCP_ROUTER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_list_ip_addr, dhcp_opt_to_user_string_list_ip_addr, dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_list_ip_addr, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* Time Servers Option */ { TAG_DHCP_TIME_SERVER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_list_ip_addr, dhcp_opt_to_user_string_list_ip_addr, dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_list_ip_addr, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* Name Servers Option */ { TAG_DHCP_NAME_SERVER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_list_ip_addr, dhcp_opt_to_user_string_list_ip_addr, dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_list_ip_addr, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* Domain Name Servers Option */ { TAG_DHCP_DOMAIN_NAME_SERVER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_list_ip_addr, dhcp_opt_to_user_string_list_ip_addr, dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_list_ip_addr, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* Log Servers Option */ { TAG_DHCP_LOG_SERVER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_list_ip_addr, dhcp_opt_to_user_string_list_ip_addr, dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_list_ip_addr, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* Cookie Servers Option */ { TAG_DHCP_COOKIE_SERVER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_list_ip_addr, dhcp_opt_to_user_string_list_ip_addr, dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_list_ip_addr, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* LPR Servers Option */ { TAG_DHCP_LPR_SERVER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_list_ip_addr, dhcp_opt_to_user_string_list_ip_addr, dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_list_ip_addr, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* Impress Servers Option */ { TAG_DHCP_IMPRESS_SERVER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_list_ip_addr, dhcp_opt_to_user_string_list_ip_addr, dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_list_ip_addr, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* Resource Location Servers Option */ { TAG_DHCP_RESOURCE_LOCATION_SERVER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_list_ip_addr, dhcp_opt_to_user_string_list_ip_addr, dhcp_opt_to_internal_string_list_ip_addr, dhcp_opt_from_network_list_ip_addr, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* Host name Option */ { TAG_DHCP_HOST_NAME, sizeof(int8_t), DHCP_OPT_STRING, DHCP_OPT_VAL_INT8, dhcp_opt_to_network_nvt_string, dhcp_opt_to_user_string_nvt_string, dhcp_opt_to_internal_string_nvt_string, dhcp_opt_from_network_nvt_string, /* FIXME: see RFC 1035 for character set restriction. */ dhcp_opt_from_user_string_nvt_string, dhcp_opt_from_internal_string_nvt_string, dhcp_opt_destroy_string, }, /* Boot File Size Option. */ { TAG_DHCP_BOOT_FILE_SIZE, sizeof(uint16_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT16, dhcp_opt_to_network_int16, dhcp_opt_to_user_string_int16, dhcp_opt_to_internal_string_int16, dhcp_opt_from_network_int16, dhcp_opt_from_user_string_int16, dhcp_opt_from_internal_string_int16, dhcp_opt_destroy_atom, }, /* Merit Dump File Option. */ { TAG_DHCP_MERIT_DUMP_FILE, sizeof(int8_t), DHCP_OPT_STRING, DHCP_OPT_VAL_INT8, dhcp_opt_to_network_nvt_string, dhcp_opt_to_user_string_nvt_string, dhcp_opt_to_internal_string_nvt_string, dhcp_opt_from_network_nvt_string, dhcp_opt_from_user_string_nvt_string, dhcp_opt_from_internal_string_nvt_string, dhcp_opt_destroy_string, }, /* Domain Name Option. */ { TAG_DHCP_DOMAIN_NAME, sizeof(int8_t), DHCP_OPT_STRING, DHCP_OPT_VAL_INT8, dhcp_opt_to_network_string, dhcp_opt_to_user_string_string, dhcp_opt_to_internal_string_string, dhcp_opt_from_network_string, dhcp_opt_from_user_string_string, dhcp_opt_from_internal_string_string, dhcp_opt_destroy_string, }, /* Swap Server Option */ { TAG_DHCP_SWAP_SERVER, IP_ADDR_LEN, DHCP_OPT_ATOM, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_ip_addr, dhcp_opt_to_user_string_ip_addr, dhcp_opt_to_internal_string_ip_addr, dhcp_opt_from_network_ip_addr, dhcp_opt_from_user_string_ip_addr, dhcp_opt_from_internal_string_ip_addr, dhcp_opt_destroy_atom, }, /* Root Path Option */ { TAG_DHCP_ROOT_PATH, sizeof(int8_t), DHCP_OPT_STRING, DHCP_OPT_VAL_INT8, dhcp_opt_to_network_nvt_string, dhcp_opt_to_user_string_nvt_string, dhcp_opt_to_internal_string_nvt_string, dhcp_opt_from_network_nvt_string, dhcp_opt_from_user_string_nvt_string, dhcp_opt_from_internal_string_nvt_string, dhcp_opt_destroy_string, }, /* Extensions Path Option */ { TAG_DHCP_EXTENSIONS_PATH, sizeof(int8_t), DHCP_OPT_STRING, DHCP_OPT_VAL_INT8, dhcp_opt_to_network_string, dhcp_opt_to_user_string_string, dhcp_opt_to_internal_string_string, dhcp_opt_from_network_string, dhcp_opt_from_user_string_string, dhcp_opt_from_internal_string_string, dhcp_opt_destroy_string, }, /* IP Forwarding Option */ { TAG_DHCP_IP_FORWARDING, sizeof(uint8_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT8, dhcp_opt_to_network_uint8, dhcp_opt_to_user_string_uint8, dhcp_opt_to_internal_string_uint8, dhcp_opt_from_network_uint8, dhcp_opt_from_user_string_uint8, dhcp_opt_from_internal_string_uint8, dhcp_opt_destroy_atom, }, /* Non Local Source Routing Option */ { TAG_DHCP_NON_LOCAL_SOURCE_ROUTING, sizeof(uint8_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT8, dhcp_opt_to_network_uint8, dhcp_opt_to_user_string_uint8, dhcp_opt_to_internal_string_uint8, dhcp_opt_from_network_uint8, dhcp_opt_from_user_string_uint8, dhcp_opt_from_internal_string_uint8, dhcp_opt_destroy_atom, }, /* Policy Filter Option */ { TAG_DHCP_POLICY_FILTER, IP_ADDR_LEN, DHCP_OPT_LIST, DHCP_OPT_VAL_ADDRESS_PAIR, dhcp_opt_to_network_ip_addr_pair, dhcp_opt_to_user_string_ip_addr_pair, dhcp_opt_to_internal_string_ip_addr_pair, dhcp_opt_from_network_list_ip_addr_pair, dhcp_opt_from_user_string_list_ip_addr, dhcp_opt_from_internal_string_list_ip_addr, dhcp_opt_destroy_list, }, /* Maximum Datagram Reassembly Size Option */ { TAG_DHCP_MAX_DGRAM_REASSUMBLY_SIZE, sizeof(uint16_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT16, dhcp_opt_to_network_uint16, dhcp_opt_to_user_string_uint16, dhcp_opt_to_internal_string_uint16, dhcp_opt_from_network_uint16, dhcp_opt_from_user_string_uint16, dhcp_opt_from_internal_string_uint16, dhcp_opt_destroy_atom, }, /* Default IP Time-to-Live Option */ { TAG_DHCP_IP_TIME_TO_LIVE, sizeof(uint8_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT8, dhcp_opt_to_network_uint8, dhcp_opt_to_user_string_uint8, dhcp_opt_to_internal_string_uint8, dhcp_opt_from_network_uint8, dhcp_opt_from_user_string_uint8, dhcp_opt_from_internal_string_uint8, dhcp_opt_destroy_atom, }, /* Path MTU Aging Timeout Option */ { TAG_DHCP_MTU_AGING_TIMEOUT, sizeof(uint32_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT32, dhcp_opt_to_network_uint32, dhcp_opt_to_user_string_uint32, dhcp_opt_to_internal_string_uint32, dhcp_opt_from_network_uint32, dhcp_opt_from_user_string_uint32, dhcp_opt_from_internal_string_uint32, dhcp_opt_destroy_atom, }, /* Path MTU Plateau Table Option */ { TAG_DHCP_MTU_PLATEAU_TABLE, sizeof(uint16_t), DHCP_OPT_LIST, DHCP_OPT_VAL_UINT16, dhcp_opt_to_network_uint16, dhcp_opt_to_user_string_uint16, dhcp_opt_to_internal_string_uint16, dhcp_opt_from_network_list_uint16, dhcp_opt_from_user_string_uint16, dhcp_opt_from_internal_string_uint16, dhcp_opt_destroy_list, }, /* Interface MTU Option */ { TAG_DHCP_INTERFACE_MTU, sizeof(uint16_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT16, dhcp_opt_to_network_uint16, dhcp_opt_to_user_string_uint16, dhcp_opt_to_internal_string_uint16, dhcp_opt_from_network_uint16, dhcp_opt_from_user_string_uint16, dhcp_opt_from_internal_string_uint16, dhcp_opt_destroy_atom, }, /* Subnets Are Local Option */ { TAG_DHCP_SUBNETS_ARE_LOCAL, sizeof(uint8_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT8, dhcp_opt_to_network_uint8, dhcp_opt_to_user_string_uint8, dhcp_opt_to_internal_string_uint8, dhcp_opt_from_network_uint8, dhcp_opt_from_user_string_uint8, dhcp_opt_from_internal_string_uint8, dhcp_opt_destroy_atom, }, /* Broadcast Address Option */ { TAG_DHCP_BROADCAST_ADDRESS, IP_ADDR_LEN, DHCP_OPT_ATOM, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_ip_addr, dhcp_opt_to_user_string_ip_addr, dhcp_opt_to_internal_string_ip_addr, dhcp_opt_from_network_ip_addr, dhcp_opt_from_user_string_ip_addr, dhcp_opt_from_internal_string_ip_addr, dhcp_opt_destroy_atom, }, /* Perform Mask Discovery Option */ { TAG_DHCP_MASK_DISCOVERY, sizeof(uint8_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT8, dhcp_opt_to_network_uint8, dhcp_opt_to_user_string_uint8, dhcp_opt_to_internal_string_uint8, dhcp_opt_from_network_uint8, dhcp_opt_from_user_string_uint8, dhcp_opt_from_internal_string_uint8, dhcp_opt_destroy_atom, }, /* Mask Supplier */ { TAG_DHCP_MASK_SUPPLIER, sizeof(uint8_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT8, dhcp_opt_to_network_uint8, dhcp_opt_to_user_string_uint8, dhcp_opt_to_internal_string_uint8, dhcp_opt_from_network_uint8, dhcp_opt_from_user_string_uint8, dhcp_opt_from_internal_string_uint8, dhcp_opt_destroy_atom, }, /* Perform Router Discovery */ { TAG_DHCP_ROUTER_DISCOVERY, sizeof(uint8_t), DHCP_OPT_ATOM, DHCP_OPT_VAL_UINT8, dhcp_opt_to_network_uint8, dhcp_opt_to_user_string_uint8, dhcp_opt_to_internal_string_uint8, dhcp_opt_from_network_uint8, dhcp_opt_from_user_string_uint8, dhcp_opt_from_internal_string_uint8, dhcp_opt_destroy_atom, }, /* Router Solicitation Address Option */ { TAG_DHCP_ROUTER_SOLICITATION, IP_ADDR_LEN, DHCP_OPT_ATOM, DHCP_OPT_VAL_ADDRESS, dhcp_opt_to_network_ip_addr, dhcp_opt_to_user_string_ip_addr, dhcp_opt_to_internal_string_ip_addr,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -