Last active
May 1, 2019 00:33
-
-
Save jpereira/ab05d733afc519ae929286d6f270e5f8 to your computer and use it in GitHub Desktop.
converting from the ISC-DHCP source code to the FreeRadius isc_dhcp format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: Jorge Pereira <[email protected]> | |
* sex fev 22 14:55:15 -03 2019 | |
* | |
* Dummy code used for get all ISC DHCP options and | |
* convert to the format expected by FreeRADIUS. | |
* | |
* Yes, That code is a trash. I don't care! | |
*/ | |
#include <stdio.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <stdlib.h> | |
#define DELAYED_ACK | |
#define FAILOVER_PROTOCOL | |
#define LDAP_CONFIGURATION | |
#define LDAP_USE_GSSAPI | |
#define LDAP_USE_SSL | |
#define RFC2563_OPTIONS | |
#define RFC2937_OPTIONS | |
#define RFC4578_OPTIONS | |
#define RFC4776_OPTIONS | |
#define RFC4833_OPTIONS | |
#define RFC5071_OPTIONS | |
#define RFC5192_OPTIONS | |
#define RFC5223_OPTIONS | |
#define RFC5417_OPTIONS | |
#define RFC5859_OPTIONS | |
#define RFC5969_OPTIONS | |
#define RFC5986_OPTIONS | |
#define RFC6011_OPTIONS | |
#define RFC6153_OPTIONS | |
#define RFC6731_OPTIONS | |
#define RFC7618_OPTIONS | |
#define RFC7710_OPTIONS | |
// It was extracted from dhcp-4.4.1/include/dhcpd.h | |
/* Server option names. */ | |
#define SV_DEFAULT_LEASE_TIME 1 | |
#define SV_MAX_LEASE_TIME 2 | |
#define SV_MIN_LEASE_TIME 3 | |
#define SV_BOOTP_LEASE_CUTOFF 4 | |
#define SV_BOOTP_LEASE_LENGTH 5 | |
#define SV_BOOT_UNKNOWN_CLIENTS 6 | |
#define SV_DYNAMIC_BOOTP 7 | |
#define SV_ALLOW_BOOTP 8 | |
#define SV_ALLOW_BOOTING 9 | |
#define SV_ONE_LEASE_PER_CLIENT 10 | |
#define SV_GET_LEASE_HOSTNAMES 11 | |
#define SV_USE_HOST_DECL_NAMES 12 | |
#define SV_USE_LEASE_ADDR_FOR_DEFAULT_ROUTE 13 | |
#define SV_MIN_SECS 14 | |
#define SV_FILENAME 15 | |
#define SV_SERVER_NAME 16 | |
#define SV_NEXT_SERVER 17 | |
#define SV_AUTHORITATIVE 18 | |
#define SV_VENDOR_OPTION_SPACE 19 | |
#define SV_ALWAYS_REPLY_RFC1048 20 | |
#define SV_SITE_OPTION_SPACE 21 | |
#define SV_ALWAYS_BROADCAST 22 | |
#define SV_DDNS_DOMAIN_NAME 23 | |
#define SV_DDNS_HOST_NAME 24 | |
#define SV_DDNS_REV_DOMAIN_NAME 25 | |
#define SV_LEASE_FILE_NAME 26 | |
#define SV_PID_FILE_NAME 27 | |
#define SV_DUPLICATES 28 | |
#define SV_DECLINES 29 | |
#define SV_DDNS_UPDATES 30 | |
#define SV_OMAPI_PORT 31 | |
#define SV_LOCAL_PORT 32 | |
#define SV_LIMITED_BROADCAST_ADDRESS 33 | |
#define SV_REMOTE_PORT 34 | |
#define SV_LOCAL_ADDRESS 35 | |
#define SV_OMAPI_KEY 36 | |
#define SV_STASH_AGENT_OPTIONS 37 | |
#define SV_DDNS_TTL 38 | |
#define SV_DDNS_UPDATE_STYLE 39 | |
#define SV_CLIENT_UPDATES 40 | |
#define SV_UPDATE_OPTIMIZATION 41 | |
#define SV_PING_CHECKS 42 | |
#define SV_UPDATE_STATIC_LEASES 43 | |
#define SV_LOG_FACILITY 44 | |
#define SV_DO_FORWARD_UPDATES 45 | |
#define SV_PING_TIMEOUT 46 | |
#define SV_RESERVE_INFINITE 47 | |
#define SV_DDNS_CONFLICT_DETECT 48 | |
#define SV_LEASEQUERY 49 | |
#define SV_ADAPTIVE_LEASE_TIME_THRESHOLD 50 | |
#define SV_DO_REVERSE_UPDATES 51 | |
#define SV_FQDN_REPLY 52 | |
#define SV_PREFER_LIFETIME 53 | |
#define SV_DHCPV6_LEASE_FILE_NAME 54 | |
#define SV_DHCPV6_PID_FILE_NAME 55 | |
#define SV_LIMIT_ADDRS_PER_IA 56 | |
#define SV_LIMIT_PREFS_PER_IA 57 | |
#define SV_DELAYED_ACK 58 | |
#define SV_MAX_ACK_DELAY 59 | |
#if defined(LDAP_CONFIGURATION) | |
# define SV_LDAP_SERVER 60 | |
# define SV_LDAP_PORT 61 | |
# define SV_LDAP_USERNAME 62 | |
# define SV_LDAP_PASSWORD 63 | |
# define SV_LDAP_BASE_DN 64 | |
# define SV_LDAP_METHOD 65 | |
# define SV_LDAP_DEBUG_FILE 66 | |
# define SV_LDAP_DHCP_SERVER_CN 67 | |
# define SV_LDAP_REFERRALS 68 | |
#if defined (LDAP_USE_SSL) | |
# define SV_LDAP_SSL 69 | |
# define SV_LDAP_TLS_REQCERT 70 | |
# define SV_LDAP_TLS_CA_FILE 71 | |
# define SV_LDAP_TLS_CA_DIR 72 | |
# define SV_LDAP_TLS_CERT 73 | |
# define SV_LDAP_TLS_KEY 74 | |
# define SV_LDAP_TLS_CRLCHECK 75 | |
# define SV_LDAP_TLS_CIPHERS 76 | |
# define SV_LDAP_TLS_RANDFILE 77 | |
#endif | |
# define SV_LDAP_INIT_RETRY 178 | |
#if defined (LDAP_USE_GSSAPI) | |
# define SV_LDAP_GSSAPI_KEYTAB 179 | |
# define SV_LDAP_GSSAPI_PRINCIPAL 180 | |
#endif | |
#endif | |
#define SV_CACHE_THRESHOLD 78 | |
#define SV_DONT_USE_FSYNC 79 | |
#define SV_DDNS_LOCAL_ADDRESS4 80 | |
#define SV_DDNS_LOCAL_ADDRESS6 81 | |
#define SV_IGNORE_CLIENT_UIDS 82 | |
#define SV_LOG_THRESHOLD_LOW 83 | |
#define SV_LOG_THRESHOLD_HIGH 84 | |
#define SV_ECHO_CLIENT_ID 85 | |
#define SV_SERVER_ID_CHECK 86 | |
#define SV_PREFIX_LEN_MODE 87 | |
#define SV_DHCPV6_SET_TEE_TIMES 88 | |
#define SV_ABANDON_LEASE_TIME 89 | |
#ifdef EUI_64 | |
#define SV_USE_EUI_64 90 | |
#define SV_PERSIST_EUI_64_LEASES 91 | |
#endif | |
#if defined (FAILOVER_PROTOCOL) | |
#define SV_CHECK_SECS_BYTE_ORDER 91 | |
#endif | |
#define SV_DDNS_DUAL_STACK_MIXED_MODE 92 | |
#define SV_DDNS_GUARD_ID_MUST_MATCH 93 | |
#define SV_DDNS_OTHER_GUARD_IS_DYNAMIC 94 | |
#define SV_RELEASE_ON_ROAM 95 | |
#define SV_LOCAL_ADDRESS6 96 | |
#define SV_BIND_LOCAL_ADDRESS6 97 | |
// It was extracted from dhcp-4.4.1/include/tree.h | |
struct universe { | |
int dummy; | |
}; | |
struct option { | |
const char *name; | |
const char *format; | |
struct universe *universe; | |
unsigned code; | |
int refcnt; | |
}; | |
static struct universe dhcp_universe; // dummy | |
static struct universe server_universe; // dummy | |
static struct universe agent_universe; // dummy | |
// It was extracted from dhcp-4.4.1/server/stables.c | |
static struct option dhcp_options[] = { | |
{ "subnet-mask", "I", &dhcp_universe, 1, 1 }, | |
{ "time-offset", "l", &dhcp_universe, 2, 1 }, | |
{ "routers", "IA", &dhcp_universe, 3, 1 }, | |
{ "time-servers", "IA", &dhcp_universe, 4, 1 }, | |
{ "ien116-name-servers", "IA", &dhcp_universe, 5, 1 }, | |
{ "domain-name-servers", "IA", &dhcp_universe, 6, 1 }, | |
{ "log-servers", "IA", &dhcp_universe, 7, 1 }, | |
{ "cookie-servers", "IA", &dhcp_universe, 8, 1 }, | |
{ "lpr-servers", "IA", &dhcp_universe, 9, 1 }, | |
{ "impress-servers", "IA", &dhcp_universe, 10, 1 }, | |
{ "resource-location-servers", "IA", &dhcp_universe, 11, 1 }, | |
{ "host-name", "t", &dhcp_universe, 12, 1 }, | |
{ "boot-size", "S", &dhcp_universe, 13, 1 }, | |
{ "merit-dump", "t", &dhcp_universe, 14, 1 }, | |
{ "domain-name", "t", &dhcp_universe, 15, 1 }, | |
{ "swap-server", "I", &dhcp_universe, 16, 1 }, | |
{ "root-path", "t", &dhcp_universe, 17, 1 }, | |
{ "extensions-path", "t", &dhcp_universe, 18, 1 }, | |
{ "ip-forwarding", "f", &dhcp_universe, 19, 1 }, | |
{ "non-local-source-routing", "f", &dhcp_universe, 20, 1 }, | |
{ "policy-filter", "IIA", &dhcp_universe, 21, 1 }, | |
{ "max-dgram-reassembly", "S", &dhcp_universe, 22, 1 }, | |
{ "default-ip-ttl", "B", &dhcp_universe, 23, 1 }, | |
{ "path-mtu-aging-timeout", "L", &dhcp_universe, 24, 1 }, | |
{ "path-mtu-plateau-table", "SA", &dhcp_universe, 25, 1 }, | |
{ "interface-mtu", "S", &dhcp_universe, 26, 1 }, | |
{ "all-subnets-local", "f", &dhcp_universe, 27, 1 }, | |
{ "broadcast-address", "I", &dhcp_universe, 28, 1 }, | |
{ "perform-mask-discovery", "f", &dhcp_universe, 29, 1 }, | |
{ "mask-supplier", "f", &dhcp_universe, 30, 1 }, | |
{ "router-discovery", "f", &dhcp_universe, 31, 1 }, | |
{ "router-solicitation-address", "I", &dhcp_universe, 32, 1 }, | |
{ "static-routes", "IIA", &dhcp_universe, 33, 1 }, | |
{ "trailer-encapsulation", "f", &dhcp_universe, 34, 1 }, | |
{ "arp-cache-timeout", "L", &dhcp_universe, 35, 1 }, | |
{ "ieee802-3-encapsulation", "f", &dhcp_universe, 36, 1 }, | |
{ "default-tcp-ttl", "B", &dhcp_universe, 37, 1 }, | |
{ "tcp-keepalive-interval", "L", &dhcp_universe, 38, 1 }, | |
{ "tcp-keepalive-garbage", "f", &dhcp_universe, 39, 1 }, | |
{ "nis-domain", "t", &dhcp_universe, 40, 1 }, | |
{ "nis-servers", "IA", &dhcp_universe, 41, 1 }, | |
{ "ntp-servers", "IA", &dhcp_universe, 42, 1 }, | |
{ "vendor-encapsulated-options", "E.", &dhcp_universe, 43, 1 }, | |
{ "netbios-name-servers", "IA", &dhcp_universe, 44, 1 }, | |
{ "netbios-dd-server", "IA", &dhcp_universe, 45, 1 }, | |
{ "netbios-node-type", "B", &dhcp_universe, 46, 1 }, | |
{ "netbios-scope", "t", &dhcp_universe, 47, 1 }, | |
{ "font-servers", "IA", &dhcp_universe, 48, 1 }, | |
{ "x-display-manager", "IA", &dhcp_universe, 49, 1 }, | |
{ "dhcp-requested-address", "I", &dhcp_universe, 50, 1 }, | |
{ "dhcp-lease-time", "L", &dhcp_universe, 51, 1 }, | |
{ "dhcp-option-overload", "B", &dhcp_universe, 52, 1 }, | |
{ "dhcp-message-type", "B", &dhcp_universe, 53, 1 }, | |
{ "dhcp-server-identifier", "I", &dhcp_universe, 54, 1 }, | |
{ "dhcp-parameter-request-list", "BA", &dhcp_universe, 55, 1 }, | |
{ "dhcp-message", "t", &dhcp_universe, 56, 1 }, | |
{ "dhcp-max-message-size", "S", &dhcp_universe, 57, 1 }, | |
{ "dhcp-renewal-time", "L", &dhcp_universe, 58, 1 }, | |
{ "dhcp-rebinding-time", "L", &dhcp_universe, 59, 1 }, | |
{ "vendor-class-identifier", "X", &dhcp_universe, 60, 1 }, | |
{ "dhcp-client-identifier", "X", &dhcp_universe, 61, 1 }, | |
{ "nwip-domain", "t", &dhcp_universe, 62, 1 }, | |
{ "nwip-suboptions", "Enwip.", &dhcp_universe, 63, 1 }, | |
{ "nisplus-domain", "t", &dhcp_universe, 64, 1 }, | |
{ "nisplus-servers", "IA", &dhcp_universe, 65, 1 }, | |
{ "tftp-server-name", "t", &dhcp_universe, 66, 1 }, | |
{ "bootfile-name", "t", &dhcp_universe, 67, 1 }, | |
{ "mobile-ip-home-agent", "IA", &dhcp_universe, 68, 1 }, | |
{ "smtp-server", "IA", &dhcp_universe, 69, 1 }, | |
{ "pop-server", "IA", &dhcp_universe, 70, 1 }, | |
{ "nntp-server", "IA", &dhcp_universe, 71, 1 }, | |
{ "www-server", "IA", &dhcp_universe, 72, 1 }, | |
{ "finger-server", "IA", &dhcp_universe, 73, 1 }, | |
{ "irc-server", "IA", &dhcp_universe, 74, 1 }, | |
{ "streettalk-server", "IA", &dhcp_universe, 75, 1 }, | |
{ "streettalk-directory-assistance-server", "IA", | |
&dhcp_universe, 76, 1 }, | |
{ "user-class", "t", &dhcp_universe, 77, 1 }, | |
{ "slp-directory-agent", "fIa", &dhcp_universe, 78, 1 }, | |
{ "slp-service-scope", "fto", &dhcp_universe, 79, 1 }, | |
/* 80 is the zero-length rapid-commit (RFC 4039) */ | |
{ "fqdn", "Efqdn.", &dhcp_universe, 81, 1 }, | |
{ "relay-agent-information", "Eagent.", &dhcp_universe, 82, 1 }, | |
/* 83 is iSNS (RFC 4174) */ | |
/* 84 is unassigned */ | |
{ "nds-servers", "IA", &dhcp_universe, 85, 1 }, | |
{ "nds-tree-name", "t", &dhcp_universe, 86, 1 }, | |
{ "nds-context", "t", &dhcp_universe, 87, 1 }, | |
/* Note: RFC4280 fails to identify if the DHCPv4 option is to use | |
* compression pointers or not. Assume not. | |
*/ | |
{ "bcms-controller-names", "D", &dhcp_universe, 88, 1 }, | |
{ "bcms-controller-address", "Ia", &dhcp_universe, 89, 1 }, | |
/* 90 is the authentication option (RFC 3118) */ | |
{ "client-last-transaction-time", "L", &dhcp_universe, 91, 1 }, | |
{ "associated-ip", "Ia", &dhcp_universe, 92, 1 }, | |
#if defined(RFC4578_OPTIONS) | |
/* Defined by RFC 4578 */ | |
{ "pxe-system-type", "Sa", &dhcp_universe, 93, 1 }, | |
{ "pxe-interface-id", "BBB", &dhcp_universe, 94, 1 }, | |
{ "pxe-client-id", "BX", &dhcp_universe, 97, 1 }, | |
#endif | |
{ "uap-servers", "t", &dhcp_universe, 98, 1 }, | |
#if defined(RFC4776_OPTIONS) | |
{ "geoconf-civic", "X", &dhcp_universe, 99, 1 }, | |
#endif | |
#if defined(RFC4833_OPTIONS) | |
{ "pcode", "t", &dhcp_universe, 100, 1 }, | |
{ "tcode", "t", &dhcp_universe, 101, 1 }, | |
#endif | |
{ "netinfo-server-address", "Ia", &dhcp_universe, 112, 1 }, | |
{ "netinfo-server-tag", "t", &dhcp_universe, 113, 1 }, | |
{ "default-url", "t", &dhcp_universe, 114, 1 }, | |
#if defined(RFC2563_OPTIONS) | |
{ "auto-config", "B", &dhcp_universe, 116, 1 }, | |
#endif | |
#if defined(RFC2937_OPTIONS) | |
{ "name-service-search", "Sa", &dhcp_universe, 117, 1 }, | |
#endif | |
{ "subnet-selection", "I", &dhcp_universe, 118, 1 }, | |
{ "domain-search", "Dc", &dhcp_universe, 119, 1 }, | |
{ "vivco", "Evendor-class.", &dhcp_universe, 124, 1 }, | |
{ "vivso", "Evendor.", &dhcp_universe, 125, 1 }, | |
#if 0 | |
/* Referenced by RFC 4578. | |
* DO NOT UNCOMMENT THESE DEFINITIONS: these names are placeholders | |
* and will not be used in future versions of the software. | |
*/ | |
{ "pxe-undefined-1", "X", &dhcp_universe, 128, 1 }, | |
{ "pxe-undefined-2", "X", &dhcp_universe, 129, 1 }, | |
{ "pxe-undefined-3", "X", &dhcp_universe, 130, 1 }, | |
{ "pxe-undefined-4", "X", &dhcp_universe, 131, 1 }, | |
{ "pxe-undefined-5", "X", &dhcp_universe, 132, 1 }, | |
{ "pxe-undefined-6", "X", &dhcp_universe, 133, 1 }, | |
{ "pxe-undefined-7", "X", &dhcp_universe, 134, 1 }, | |
{ "pxe-undefined-8", "X", &dhcp_universe, 135, 1 }, | |
#endif | |
#if defined(RFC5192_OPTIONS) | |
{"pana-agent", "Ia", &dhcp_universe, 136, 1 }, | |
#endif | |
#if defined(RFC5223_OPTIONS) | |
{"v4-lost", "d", &dhcp_universe, 137, 1 }, | |
#endif | |
#if defined(RFC5417_OPTIONS) | |
{"capwap-ac-v4", "Ia", &dhcp_universe, 138, 1 }, | |
#endif | |
#if defined(RFC6011_OPTIONS) | |
{ "sip-ua-cs-domains", "Dc", &dhcp_universe, 141, 1 }, | |
#endif | |
#if defined(RFC6153_OPTIONS) | |
{ "ipv4-address-andsf", "IA", &dhcp_universe, 142, 1 }, | |
#endif | |
#if defined(RFC6731_OPTIONS) | |
{ "rdnss-selection", "BIID", &dhcp_universe, 146, 1 }, | |
#endif | |
#if defined(RFC5859_OPTIONS) | |
{ "tftp-server-address", "Ia", &dhcp_universe, 150, 1 }, | |
#endif | |
#if defined(RFC7618_OPTIONS) | |
{ "v4-portparams", "BBS", &dhcp_universe, 159, 1 }, | |
#endif | |
#if defined(RFC7710_OPTIONS) | |
{ "v4-captive-portal", "t", &dhcp_universe, 160, 1 }, | |
#endif | |
#if defined(RFC5071_OPTIONS) | |
#if 0 | |
/* Option 208 has been officially deprecated. Do NOT define it */ | |
{ "pxelinux-magic", "BBBB", &dhcp_universe, 208, 1 }, | |
#endif | |
{ "loader-configfile", "t", &dhcp_universe, 209, 1 }, | |
{ "loader-pathprefix", "t", &dhcp_universe, 210, 1 }, | |
{ "loader-reboottime", "L", &dhcp_universe, 211, 1 }, | |
#endif | |
#if defined(RFC5969_OPTIONS) | |
{ "option-6rd", "BB6Ia", &dhcp_universe, 212, 1 }, | |
#endif | |
#if defined(RFC5986_OPTIONS) | |
{"v4-access-domain", "d", &dhcp_universe, 213, 1 }, | |
#endif | |
{ NULL, NULL, NULL, 0, 0 } | |
}; | |
// It was extracted from dhcp-4.4.1/server/stables.c | |
static struct option agent_options[] = { | |
{ "circuit-id", "X", &agent_universe, 1, 1 }, | |
{ "remote-id", "X", &agent_universe, 2, 1 }, | |
{ "agent-id", "I", &agent_universe, 3, 1 }, | |
{ "DOCSIS-device-class", "L", &agent_universe, 4, 1 }, | |
{ "link-selection", "I", &agent_universe, 5, 1 }, | |
{ "relay-port", "Z", &agent_universe, 19, 1 }, | |
{ NULL, NULL, NULL, 0, 0 } | |
}; | |
// It was extracted from dhcp-4.4.1/server/stables.c | |
static struct option server_options[] = { | |
{ "default-lease-time", "T", &server_universe, 1, 1 }, | |
{ "max-lease-time", "T", &server_universe, 2, 1 }, | |
{ "min-lease-time", "T", &server_universe, 3, 1 }, | |
{ "dynamic-bootp-lease-cutoff", "T", &server_universe, 4, 1 }, | |
{ "dynamic-bootp-lease-length", "L", &server_universe, 5, 1 }, | |
{ "boot-unknown-clients", "f", &server_universe, 6, 1 }, | |
{ "dynamic-bootp", "f", &server_universe, 7, 1 }, | |
{ "allow-bootp", "f", &server_universe, 8, 1 }, | |
{ "allow-booting", "f", &server_universe, 9, 1 }, | |
{ "one-lease-per-client", "f", &server_universe, 10, 1 }, | |
{ "get-lease-hostnames", "f", &server_universe, 11, 1 }, | |
{ "use-host-decl-names", "f", &server_universe, 12, 1 }, | |
{ "use-lease-addr-for-default-route", "f", &server_universe, 13, 1 }, | |
{ "min-secs", "B", &server_universe, 14, 1 }, | |
{ "filename", "t", &server_universe, 15, 1 }, | |
{ "server-name", "t", &server_universe, 16, 1 }, | |
{ "next-server", "I", &server_universe, 17, 1 }, | |
{ "authoritative", "f", &server_universe, 18, 1 }, | |
{ "vendor-option-space", "U", &server_universe, 19, 1 }, | |
{ "always-reply-rfc1048", "f", &server_universe, 20, 1 }, | |
{ "site-option-space", "X", &server_universe, 21, 1 }, | |
{ "always-broadcast", "f", &server_universe, 22, 1 }, | |
{ "ddns-domainname", "t", &server_universe, 23, 1 }, | |
{ "ddns-hostname", "t", &server_universe, 24, 1 }, | |
{ "ddns-rev-domainname", "t", &server_universe, 25, 1 }, | |
{ "lease-file-name", "t", &server_universe, 26, 1 }, | |
{ "pid-file-name", "t", &server_universe, 27, 1 }, | |
{ "duplicates", "f", &server_universe, 28, 1 }, | |
{ "declines", "f", &server_universe, 29, 1 }, | |
{ "ddns-updates", "f", &server_universe, 30, 1 }, | |
{ "omapi-port", "S", &server_universe, 31, 1 }, | |
{ "local-port", "S", &server_universe, 32, 1 }, | |
{ "limited-broadcast-address", "I", &server_universe, 33, 1 }, | |
{ "remote-port", "S", &server_universe, 34, 1 }, | |
{ "local-address", "I", &server_universe, 35, 1 }, | |
{ "omapi-key", "d", &server_universe, 36, 1 }, | |
{ "stash-agent-options", "f", &server_universe, 37, 1 }, | |
{ "ddns-ttl", "T", &server_universe, 38, 1 }, | |
{ "ddns-update-style", "Nddns-styles.", &server_universe, 39, 1 }, | |
{ "client-updates", "f", &server_universe, 40, 1 }, | |
{ "update-optimization", "f", &server_universe, 41, 1 }, | |
{ "ping-check", "f", &server_universe, 42, 1 }, | |
{ "update-static-leases", "f", &server_universe, 43, 1 }, | |
{ "log-facility", "Nsyslog-facilities.", | |
&server_universe, 44, 1 }, | |
{ "do-forward-updates", "f", &server_universe, 45, 1 }, | |
{ "ping-timeout", "T", &server_universe, 46, 1 }, | |
{ "infinite-is-reserved", "f", &server_universe, 47, 1 }, | |
{ "update-conflict-detection", "f", &server_universe, 48, 1 }, | |
{ "leasequery", "f", &server_universe, 49, 1 }, | |
{ "adaptive-lease-time-threshold", "B", &server_universe, 50, 1 }, | |
{ "do-reverse-updates", "f", &server_universe, 51, 1 }, | |
{ "fqdn-reply", "f", &server_universe, 52, 1 }, | |
{ "preferred-lifetime", "T", &server_universe, 53, 1 }, | |
{ "dhcpv6-lease-file-name", "t", &server_universe, 54, 1 }, | |
{ "dhcpv6-pid-file-name", "t", &server_universe, 55, 1 }, | |
{ "limit-addrs-per-ia", "L", &server_universe, 56, 1 }, | |
{ "limit-prefs-per-ia", "L", &server_universe, 57, 1 }, | |
/* Assert a configuration parsing error if delayed-ack isn't compiled in. */ | |
#if defined(DELAYED_ACK) | |
{ "delayed-ack", "S", &server_universe, 58, 1 }, | |
{ "max-ack-delay", "L", &server_universe, 59, 1 }, | |
#endif | |
#if defined(LDAP_CONFIGURATION) | |
{ "ldap-server", "t", &server_universe, 60, 1 }, | |
{ "ldap-port", "d", &server_universe, 61, 1 }, | |
{ "ldap-username", "t", &server_universe, 62, 1 }, | |
{ "ldap-password", "t", &server_universe, 63, 1 }, | |
{ "ldap-base-dn", "t", &server_universe, 64, 1 }, | |
{ "ldap-method", "Nldap-methods.", &server_universe, 65, 1 }, | |
{ "ldap-debug-file", "t", &server_universe, 66, 1 }, | |
{ "ldap-dhcp-server-cn", "t", &server_universe, 67, 1 }, | |
{ "ldap-referrals", "f", &server_universe, 68, 1 }, | |
#if defined(LDAP_USE_SSL) | |
{ "ldap-ssl", "Nldap-ssl-usage.", &server_universe, 69, 1 }, | |
{ "ldap-tls-reqcert", "Nldap-tls-reqcert.", &server_universe, 70, 1 }, | |
{ "ldap-tls-ca-file", "t", &server_universe, 71, 1 }, | |
{ "ldap-tls-ca-dir", "t", &server_universe, 72, 1 }, | |
{ "ldap-tls-cert", "t", &server_universe, 73, 1 }, | |
{ "ldap-tls-key", "t", &server_universe, 74, 1 }, | |
{ "ldap-tls-crlcheck", "Nldap-tls-crlcheck.", &server_universe, 75, 1 }, | |
{ "ldap-tls-ciphers", "t", &server_universe, 76, 1 }, | |
{ "ldap-tls-randfile", "t", &server_universe, 77, 1 }, | |
{ "ldap-init-retry", "d", &server_universe, SV_LDAP_INIT_RETRY, 1 }, | |
#endif /* LDAP_USE_SSL */ | |
#if defined(LDAP_USE_GSSAPI) | |
{ "ldap-gssapi-keytab", "t", &server_universe, SV_LDAP_GSSAPI_KEYTAB, 1}, | |
{ "ldap-gssapi-principal", "t", &server_universe, SV_LDAP_GSSAPI_PRINCIPAL, 1}, | |
#endif /* LDAP_USE_GSSAPI */ | |
#endif /* LDAP_CONFIGURATION */ | |
{ "dhcp-cache-threshold", "B", &server_universe, 78, 1 }, | |
{ "dont-use-fsync", "f", &server_universe, 79, 1 }, | |
{ "ddns-local-address4", "I", &server_universe, 80, 1 }, | |
{ "ddns-local-address6", "6", &server_universe, 81, 1 }, | |
{ "ignore-client-uids", "f", &server_universe, 82, 1 }, | |
{ "log-threshold-low", "B", &server_universe, 83, 1 }, | |
{ "log-threshold-high", "B", &server_universe, 84, 1 }, | |
{ "echo-client-id", "f", &server_universe, SV_ECHO_CLIENT_ID, 1 }, | |
{ "server-id-check", "f", &server_universe, SV_SERVER_ID_CHECK, 1 }, | |
{ "prefix-length-mode", "Nprefix_length_modes.", &server_universe, SV_PREFIX_LEN_MODE, 1 }, | |
{ "dhcpv6-set-tee-times", "f", &server_universe, SV_DHCPV6_SET_TEE_TIMES, 1 }, | |
{ "abandon-lease-time", "T", &server_universe, SV_ABANDON_LEASE_TIME, 1 }, | |
#ifdef EUI_64 | |
{ "use-eui-64", "f", &server_universe, SV_USE_EUI_64, 1 }, | |
{ "persist-eui-64-leases", "f", &server_universe, SV_PERSIST_EUI_64_LEASES, 1 }, | |
#endif | |
#if defined (FAILOVER_PROTOCOL) | |
{ "check-secs-byte-order", "f", &server_universe, SV_CHECK_SECS_BYTE_ORDER, 1 }, | |
#endif | |
{ "ddns-dual-stack-mixed-mode", "f", &server_universe, SV_DDNS_DUAL_STACK_MIXED_MODE, 1 }, | |
{ "ddns-guard-id-must-match", "f", &server_universe, SV_DDNS_GUARD_ID_MUST_MATCH, 1 }, | |
{ "ddns-other-guard-is-dynamic", "f", &server_universe, SV_DDNS_OTHER_GUARD_IS_DYNAMIC, 1 }, | |
{ "release-on-roam", "f", &server_universe, SV_RELEASE_ON_ROAM, 1 }, | |
{ "local-address6", "6", &server_universe, SV_LOCAL_ADDRESS6, 1 }, | |
{ "bind-local-address6", "f", &server_universe, SV_BIND_LOCAL_ADDRESS6, 1 }, | |
{ NULL, NULL, NULL, 0, 0 } | |
}; | |
struct option_datatype { | |
char fr_type[64]; | |
char fr_dict_type[64]; | |
char comment[64]; | |
int is_array; | |
}; | |
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0])) | |
struct option_datatype *convert_isc2fr_isc(const char *format) { | |
static struct option_datatype d; | |
const char *fr_type; | |
const char *fr_dict_type; | |
const char *comment; | |
switch (format[0]) { | |
case 'L': | |
fr_type = "UINT32"; | |
fr_dict_type = "integer"; | |
comment = "integer uint32_t"; | |
break; | |
case 'l': | |
fr_type = "INT32"; | |
fr_dict_type = "integer"; | |
comment = "integer int32_t"; | |
break; | |
case 's': | |
fr_type = "INT16"; | |
fr_dict_type = "short"; | |
comment = "integer int16_t"; | |
break; | |
case 'S': | |
fr_type = "UINT16"; | |
fr_dict_type = "short"; | |
comment = "integer uint16_t"; | |
break; | |
case 'b': | |
fr_type = "INT8"; | |
fr_dict_type = "octets"; | |
comment = "integer int8_t"; | |
break; | |
case 'B': | |
fr_type = "UINT8"; | |
fr_dict_type = "octets"; | |
comment = "integer uint8_t"; | |
break; | |
case 'f': | |
fr_type = "BOOL"; | |
fr_dict_type = "bool"; | |
comment = "boolean can be true, false or ignore"; | |
break; | |
case '6': | |
fr_type = "IPADDR6"; | |
fr_dict_type = "ipaddr"; | |
comment = "ipv6 addr"; | |
break; | |
case 'I': | |
fr_type = "IPADDR"; | |
fr_dict_type = "ipaddr"; | |
comment = "ipaddr or hostname"; | |
break; | |
case 'D': | |
fr_type = "STRING"; | |
fr_dict_type = "string"; | |
comment = "domain list"; | |
break; | |
case 'd': | |
fr_type = "STRING"; | |
fr_dict_type = "string"; | |
comment = "domain name"; | |
break; | |
case 't': | |
fr_type = "STRING"; | |
fr_dict_type = "string"; | |
comment = "text string"; | |
break; | |
case 'U': | |
fr_type = "RAW"; | |
fr_dict_type = "raw"; | |
comment = "vendor option declaration"; | |
break; | |
case 'X': | |
fr_type = "RAW"; | |
fr_dict_type = "raw"; | |
comment = "vendor option declaration statement"; | |
break; | |
case 'N': | |
fr_type = "STRING"; | |
fr_dict_type = "string"; | |
comment = "string options. e.g: opt1, opt2 or opt3"; | |
d.is_array = 1; | |
break; | |
case 'E': | |
fr_type = "RAW"; | |
fr_dict_type = "raw"; | |
comment = "vendor option declaration"; | |
break; | |
case 'Z': | |
fr_type = "PORT"; | |
fr_dict_type = "short"; | |
comment = "Zero-lenght option"; | |
break; | |
case 'T': | |
fr_type = "UINT32"; | |
fr_dict_type = "integer"; | |
comment = "Lease time interval"; | |
break; | |
default: | |
fr_type = "UNKNOWN"; | |
fr_dict_type = "$$$$$$UNKNOWN$$$$$$"; | |
comment = "????????????"; | |
} | |
if (*(format + 1)) { | |
sprintf(d.comment, "%s [arg1, ... ]", comment); | |
sprintf(d.fr_type, "%s,", fr_type); | |
sprintf(d.fr_dict_type, "%s array", fr_dict_type); | |
d.is_array = 1; | |
} else { | |
strcpy(d.comment, comment); | |
strcpy(d.fr_type, fr_type); | |
strcpy(d.fr_dict_type, fr_dict_type); | |
d.is_array = 0; | |
} | |
return (struct option_datatype *)&d; | |
} | |
int config_sort(const void *_a, const void *_b) | |
{ | |
struct option *a = (struct option *)_a; | |
struct option *b = (struct option *)_b; | |
if (a->name == NULL || b->name == NULL) | |
return 0; | |
return strcasecmp(a->name, b->name); | |
} | |
int print_fr_isc_dhcp_struct() { | |
struct option *s = &server_options[0]; | |
qsort(server_options, ARRAY_SIZE(server_options), sizeof(struct option), config_sort); | |
for(; s->name != NULL; s++) { | |
struct option_datatype *fmt = convert_isc2fr_isc(s->format); | |
printf("\t{ \"%s %s\", ISC_NOOP, NULL, NULL, 1}, // %s\n", | |
s->name, fmt->fr_type, fmt->comment); | |
} | |
return 0; | |
} | |
int print_fr_isc_dict() { | |
struct option *d = &dhcp_options[0]; | |
printf("\n"); | |
printf("# dhcp-options\n"); | |
for (; d->name != NULL; d++) { | |
const char *name = d->name; | |
struct option_datatype *fmt = convert_isc2fr_isc(d->format); | |
printf("ATTRIBUTE\t%s\t\t%d\t%s\n", name, d->code, fmt->fr_dict_type); | |
if (d->code == 82) { | |
struct option *a = &agent_options[0]; | |
for( ; a->name != NULL; a++) { | |
const char *name = a->name; | |
struct option_datatype *fmt = convert_isc2fr_isc(a->format); | |
printf("ATTRIBUTE\tagent.%s\t\t82.%d\t%s\n", name, a->code, fmt->fr_dict_type); | |
} | |
} | |
} | |
return 0; | |
} | |
struct arg_opt { | |
const char *opt; | |
int (*func)(); | |
}; | |
static struct arg_opt opts[] = { | |
{ "fr_list", print_fr_isc_dhcp_struct }, | |
{ "fr_dict", print_fr_isc_dict }, | |
{ NULL, NULL } | |
}; | |
int main(int argc, char *argv[]) { | |
int i=0; | |
const char *opt = argv[1]; | |
if (argc < 2) goto bye; | |
while (*opt == '-') opt++; | |
if (!*opt) goto bye; | |
for(i=0; opts[i].opt; i++) { | |
if (!strcmp(opt, opts[i].opt)) return opts[i].func(); | |
} | |
fprintf(stderr, "Option '%s' is not found.\n", opt); | |
bye: | |
printf("Usage: %s <option>\n", argv[0]); | |
printf("Options:\n\n"); | |
for(i=0; opts[i].opt; i++) { | |
printf("\t--%s\n", opts[i].opt); | |
} | |
return -1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment