1 /*
2  * Project    : ipv6calc
3  * File       : ipv6calcoptions.h
4  * Version    : $Id: 147da5a50902b61a09f58504ba5347b94ae318af $
5  * Copyright  : 2013-2020 by Peter Bieringer <pb (at) bieringer.de>
6  *
7  * Information:
8  *  Header file containing options
9  */
10 
11 #include <getopt.h>
12 #include <stdio.h>
13 
14 
15 /* Options */
16 
17 /* define short options
18  *  d <debugvalue> = debug value
19  */
20 
21 /* define common short options */
22 static char *ipv6calc_shortopts_common = "d:qV";
23 
24 /* define common long options */
25 static struct option ipv6calc_longopts_common[] = {
26 	{"debug"  , 1, NULL, (int) 'd' },
27 	{"quiet"  , 0, NULL, (int) 'q' },
28 	{"verbose", 0, NULL, (int) 'V' },
29 
30 	/* dummy catch if support is not compiled in */
31 #ifndef SUPPORT_IP2LOCATION
32 	{"disable-ip2location"         , 0, NULL, OPTION_NOOP },
33 	{"db-ip2location-disable"      , 0, NULL, OPTION_NOOP },
34 #endif
35 
36 	/* GeoIP(legacy) database options (EOS since 3.0.0, TODO remove 4.0.0) */
37 	{"db-geoip"                    , 1, NULL, DB_EOS_geoip_ipv4         },
38 	{"db-geoip-ipv4"               , 1, NULL, DB_EOS_geoip_ipv4         },
39 	{"db-geoip-ipv6"               , 1, NULL, DB_EOS_geoip_ipv6         },
40 	{"db-geoip-default"            , 0, NULL, (int) 'G'             },
41 	{"db-geoip-ipv4-default"       , 0, NULL, DB_EOS_geoip_ipv4_default },
42 	{"db-geoip-ipv6-default"       , 0, NULL, DB_EOS_geoip_ipv6_default },
43 	{"disable-geoip"               , 0, NULL, DB_EOS_geoip_disable       },
44 	{"db-geoip-disable"            , 0, NULL, DB_EOS_geoip_disable       },
45 	{"db-geoip-dir"                , 1, NULL, DB_EOS_geoip_dir           },
46 	{"db-geoip-lib"                , 1, NULL, DB_EOS_geoip_lib           },
47 
48 #ifndef SUPPORT_GEOIP2
49 	{"disable-geoip2"              , 0, NULL, OPTION_NOOP },
50 	{"db-geoip2-disable"           , 0, NULL, OPTION_NOOP },
51 #endif
52 
53 	/* db-ip.com(BerkeleyDB) database options (EOS since 3.0.0, TODO remove 4.0.0) */
54 	{"disable-dbip"                , 0, NULL, DB_EOS_dbip_disable       },
55 	{"db-dbip-disable"             , 0, NULL, DB_EOS_dbip_disable       },
56 	{"db-dbip-dir"                 , 1, NULL, DB_EOS_dbip_dir           },
57 	{"db-dbip-comm-to-free-switch-min-delta-months", 1, NULL, DB_EOS_dbip_comm_to_free_switch_min_delta_months },
58 	{"db-dbip-only-type", 1, NULL, DB_EOS_dbip_only_type },
59 
60 #ifndef SUPPORT_DBIP2
61 	{"disable-dbip2"               , 0, NULL, OPTION_NOOP },
62 	{"db-dbip2-disable"            , 0, NULL, OPTION_NOOP },
63 #endif
64 
65 #ifndef SUPPORT_EXTERNAL
66 	{"disable-external"            , 0, NULL, OPTION_NOOP },
67 	{"db-external-disable"         , 0, NULL, OPTION_NOOP },
68 #endif
69 
70 #ifndef SUPPORT_BUILTIN
71 	{"disable-builtin"             , 0, NULL, OPTION_NOOP },
72 	{"db-builtin-disable"          , 0, NULL, OPTION_NOOP },
73 #endif
74 };
75 
76 #ifdef SUPPORT_IP2LOCATION
77 static char *ipv6calc_shortopts_ip2location = "L";
78 
79 static struct option ipv6calc_longopts_ip2location[] = {
80 	/* database options (EOS since 3.0.0, TODO remove in 4.0.0) */
81 	{"db-ip2location-ipv4"         , 1, NULL, DB_EOS_ip2location_ipv4   },
82 	{"db-ip2location-ipv6"         , 1, NULL, DB_EOS_ip2location_ipv6   },
83 	{"db-ip2location-default"      , 0, NULL, (int) 'L'             },
84 	{"db-ip2location-ipv4-default" , 0, NULL, DB_EOS_geoip_ipv4_default },
85 	{"db-ip2location-ipv6-default" , 0, NULL, DB_EOS_geoip_ipv6_default },
86 
87 	/* database options (new) */
88 	{"disable-ip2location"         , 0, NULL, DB_ip2location_disable },
89 	{"db-ip2location-disable"      , 0, NULL, DB_ip2location_disable },
90 	{"db-ip2location-dir"          , 1, NULL, DB_ip2location_dir     },
91 
92 	/* database selection control */
93 	{"db-ip2location-lite-to-sample-autoswitch-max-delta-months", 1, NULL, DB_ip2location_lite_to_sample_autoswitch_max_delta_months },
94 	{"db-ip2location-comm-to-lite-switch-min-delta-months", 1, NULL, DB_ip2location_comm_to_lite_switch_min_delta_months },
95 	{"db-ip2location-only-type", 1, NULL, DB_ip2location_only_type },
96 	{"db-ip2location-allow-softlinks", 0, NULL, DB_ip2location_allow_softlinks },
97 
98 #ifdef SUPPORT_IP2LOCATION_DYN
99 	{"db-ip2location-lib"          , 1, NULL, DB_ip2location_lib     },
100 #endif // SUPPORT_IP2LOCATION_DYN
101 };
102 #endif // SUPPORT_IP2LOCATION
103 
104 #ifdef SUPPORT_GEOIP2
105 static char *ipv6calc_shortopts_geoip2 = "";
106 
107 static struct option ipv6calc_longopts_geoip2[] = {
108 	{"disable-geoip2"              , 0, NULL, DB_geoip2_disable       },
109 	{"db-geoip2-disable"           , 0, NULL, DB_geoip2_disable       },
110 	{"db-geoip2-dir"               , 1, NULL, DB_geoip2_dir           },
111 };
112 #endif // SUPPORT_GEOIP2
113 
114 #ifdef SUPPORT_MMDB
115 static char *ipv6calc_shortopts_mmdb = "M";
116 
117 static struct option ipv6calc_longopts_mmdb[] = {
118 	/* database options */
119 	{"disable-mmdb"               , 0, NULL, DB_mmdb_disable       },
120 	{"db-mmdb-disable"            , 0, NULL, DB_mmdb_disable       },
121 #ifdef SUPPORT_MMDB_DYN
122 	{"db-mmdb-lib"                , 1, NULL, DB_mmdb_lib           },
123 #endif // SUPPORT_MMDB_DYN
124 };
125 #endif // SUPPORT_MMDB
126 
127 #ifdef SUPPORT_DBIP2
128 static char *ipv6calc_shortopts_dbip2 = "";
129 
130 static struct option ipv6calc_longopts_dbip2[] = {
131 	{"disable-dbip2"               , 0, NULL, DB_dbip2_disable       },
132 	{"db-dbip2-disable"             , 0, NULL, DB_dbip2_disable       },
133 	{"db-dbip2-dir"                 , 1, NULL, DB_dbip2_dir           },
134 	{"db-dbip2-comm-to-free-switch-min-delta-months", 1, NULL, DB_dbip2_comm_to_free_switch_min_delta_months },
135 	{"db-dbip2-only-type", 1, NULL, DB_dbip2_only_type },
136 };
137 #endif // SUPPORT_DBIP2
138 
139 #ifdef SUPPORT_EXTERNAL
140 static char *ipv6calc_shortopts_external = "";
141 
142 static struct option ipv6calc_longopts_external[] = {
143 	{"disable-external"            , 0, NULL, DB_external_disable   },
144 	{"db-external-disable"         , 0, NULL, DB_external_disable   },
145 	{"db-external-dir"             , 1, NULL, DB_external_dir       },
146 };
147 #endif // SUPPORT_EXTERNAL
148 
149 #ifdef SUPPORT_BUILTIN
150 static char *ipv6calc_shortopts_builtin = "";
151 
152 static struct option ipv6calc_longopts_builtin[] = {
153 	{"disable-builtin"             , 0, NULL, DB_builtin_disable    },
154 	{"db-builtin-disable"          , 0, NULL, DB_builtin_disable    },
155 };
156 #endif // SUPPORT_BUILTIN
157 
158 #if defined SUPPORT_EXTERNAL || defined SUPPORT_DBIP || defined SUPPORT_GEOIP || SUPPORT_IP2LOCATION || defined SUPPORT_MMDB || defined SUPPORT_GEOIP2 || defined SUPPORT_DBIP2
159 static char *ipv6calc_shortopts_db_common = "";
160 
161 static struct option ipv6calc_longopts_db_common[] = {
162 	{"db-priorization"             , 1, NULL, DB_common_priorization },
163 };
164 #endif
165 
166 /* define common anonymization short options */
167 static char *ipv6calc_shortopts_common_anon = "";
168 
169 /* define common anonymization long options */
170 static struct option ipv6calc_longopts_common_anon[] = {
171 	{ "anonymize-standard"	, 0, NULL, CMD_ANON_PRESET_STANDARD },
172 	{ "anonymize-careful"	, 0, NULL, CMD_ANON_PRESET_CAREFUL  },
173 	{ "anonymize-paranoid"	, 0, NULL, CMD_ANON_PRESET_PARANOID },
174 	{ "anonymize-preset"	, 1, NULL, CMD_ANON_PRESET_OPTION   },
175 	{ "ap"			, 1, NULL, CMD_ANON_PRESET_OPTION   },
176 	{ "anonymize-method"	, 1, NULL, CMD_ANON_METHOD_OPTION   },
177 	{ "mask-ipv4"		, 1, NULL, CMD_ANON_MASK_IPV4 },
178 	{ "mask-ipv6"		, 1, NULL, CMD_ANON_MASK_IPV6 },
179 	{ "mask-iid"		, 1, NULL, CMD_ANON_MASK_IID },
180 	{ "mask-eui64"		, 1, NULL, CMD_ANON_MASK_EUI64 },
181 	{ "mask-mac"		, 1, NULL, CMD_ANON_MASK_MAC },
182 	{ "mask-autoadjust"	, 1, NULL, CMD_ANON_MASK_AUTOADJUST },
183 };
184