00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef MN_H
00014 #define MN_H
00015
00016 #include "config.h"
00017
00018 #include <stdio.h>
00019 #include <syslog.h>
00020 #include <asm/types.h>
00021 #include <sys/types.h>
00022 #include <sys/socket.h>
00023 #include <sys/time.h>
00024 #include <sys/un.h>
00025 #ifdef DYN_TARGET_LINUX
00026 #if 1
00027
00028
00029 #include <linux/if.h>
00030 #else
00031 #include <net/if.h>
00032 #endif
00033 #endif
00034 #ifdef DYN_TARGET_WINDOWS
00035 #include "windows_extra.h"
00036 #endif
00037
00038 #include "message.h"
00039 #include "list.h"
00040 #include "mn_agentadv.h"
00041 #include "dyn_api.h"
00042 #include "dyn_ip.h"
00043
00044
00045
00046 #ifndef TRUE
00047 #define TRUE 1
00048 #endif
00049 #ifndef FALSE
00050 #define FALSE 0
00051 #endif
00052
00053 #define DEBUG_MESSAGES 'M'
00054 #define DEBUG_STATES 'S'
00055 #define DEBUG_INFO 'I'
00056 #define DEBUG_API 'A'
00057 #define DEBUG_AGENTADV '1'
00058 #define DEBUG_HANDLERS '2'
00059 #define DEBUG_TIMERS 't'
00060
00061
00062
00063 #define MN_ENABLE_TUNNELING
00064
00065
00066 #define MN_ENABLE_VALIDATION
00067
00068
00069
00070
00071
00072 #define MIN_REGISTRATION_DELAY 1000000
00073 #define MIN_SOLICITATION_DELAY 1000000
00074
00075 #define ASSERT assert
00076 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
00077 #define MAX(x, y) (((x) > (y)) ? (x) : (y))
00078 #define LOG2(lev, fmt, args...) { DEBUG(DEBUG_INFO, fmt, ## args); \
00079 syslog(lev, fmt, ## args); }
00080
00081
00082 #define MAXMSG 2048
00083
00084 #define MAX_INTERFACES 10
00085 #define DEFAULT_INTERFACE_PRIORITY 100
00086
00087 #define SYSLOG_IDENT "mobile node"
00088 #define SYSLOG_OPTIONS LOG_PID | LOG_CONS
00089
00090
00091 #define TIMER_GEN 0
00092
00093 #define TIMER_LIFETIME 1
00094
00095 #define TIMER_ADV 2
00096
00097 #define TIMER_REQUEST 3
00098
00099 #define TIMER_REREG 4
00100
00101 #define TIMER_WLAN_AP_POLL 5
00102
00103 #define TIMER_SOLICITATION 6
00104 #define TIMER_COUNT 7
00105
00106
00107
00108 #define REG_DISC 0
00109 #define REG_CONNECT 1
00110 #define REG_REREG 2
00111
00112
00113
00114
00115 #define CON_HA 0
00116 #define CON_FA 1
00117
00118
00119 #define STATE_INIT 0
00120 #define STATE_TIMEOUT 1
00121
00122
00123 #define OLD_TUNNEL_EXTRA_TIME 3
00124
00125
00126
00127
00128
00129 #define MIN_REGISTRATION_TIME 1
00130 #define MAX_REGISTRATION_TIME 32
00131
00132 #define DEREGISTRATION_INTERVAL 8
00133
00134
00135 #define DEFAULT_PRIO_DEGRADE_INITIAL 10
00136
00137
00138
00139 #define DEFAULT_PRIO_DEGRADE_FACTOR 2
00140
00141
00142
00143 #define DEFAULT_PRIO_DEGRADE_DEGRADE 0.9
00144
00145
00146
00147 #define SOLICITATION_PRIO_DEGRADE 10
00148
00149
00150
00151 #define MAX_AGENTSOL_REPLY_WAIT 1500000
00152
00153
00154 #define SOLICITATION_INTERVALS {1, 1, 1, 2, 4, 8, 16, 32, 64}
00155
00156
00157
00158
00159 #define MAX_RANDOM_SOLICITATION_DELAY 500000
00160
00161
00162 #define NORMAL_REREGISTRATION_TIME 32
00163
00164
00165
00166 #define MN_AAA_REG_TIME 15
00167
00168
00169 #define MAX_DEREGISTRATION_TO_HA 5
00170
00171
00172 #define MIN_ALLOWED_LIFETIME 1
00173
00174
00175 #define MAX_HA_ERRORS 5
00176
00177
00178 #define MN_CONF_FILE "dynmnd.conf"
00179 #define MN_LOCAL_CONF_FILE MN_CONF_FILE
00180 #define MN_GLOBAL_CONF_FILE SYSCONFDIR "/" MN_CONF_FILE
00181
00182
00183 #define MN_PID_FILE PIDDIR "/dynmnd.pid"
00184
00185 #define MAXFILENAMELEN 256
00186 #define MAXSHAREDSECRETLEN 32
00187 #define MAXDEVICENAMELEN 80
00188 #define MAXOWNERNAMELEN 8
00189 #define MAXGROUPNAMELEN 8
00190 #define MAXROUTELEN 256
00191
00192 #define MN_DEFAULT_TUNNEL_LIFETIME 400
00193 #define MN_DEFAULT_SYSLOG_FACILITY LOG_LOCAL0
00194
00195
00196
00197
00198
00199
00200
00201
00202 #define MNDECAPS_ROUTE_DEFAULT 0
00203 #define MNDECAPS_ROUTE_HOME_NET 1
00204 #define MNDECAPS_ROUTE_NONE 2
00205
00206 #define TUNMODE_AUTO_REVERSE 1
00207 #define TUNMODE_AUTO_TRIANGLE 2
00208 #define TUNMODE_REVERSE 3
00209 #define TUNMODE_TRIANGLE 4
00210
00211
00212
00213
00214 enum mobile_state {
00215 MN_STARTUP,
00216 MN_DISCONNECTED,
00217 MN_FIND_AGENT,
00218 MN_PASSIVE_FIND,
00219 MN_REQUEST_TUNNEL,
00220 MN_CONNECTED,
00221 MN_CLOSE_FOR_HOME,
00222 MN_AT_HOME,
00223 MN_ERROR,
00224 MN_STOP,
00225 MN_STATE_COUNT
00226 };
00227
00228
00229
00230
00231 struct fa_spi_entry {
00232 struct node node;
00233 int spi;
00234 struct in_addr addr;
00235 int alg;
00236 unsigned char shared_secret[MAXSHAREDSECRETLEN];
00237 int shared_secret_len;
00238 time_t created;
00239
00240 unsigned int lifetime;
00241
00242 };
00243
00244 struct ignore_iflist_entry {
00245 struct node node;
00246 char ifname[IFNAMSIZ];
00247 };
00248
00249 struct dev_prio_entry {
00250 struct node node;
00251 int priority;
00252 unsigned char name[MAXDEVICENAMELEN];
00253 };
00254
00255 struct alt_ha_entry {
00256 struct node node;
00257 struct in_addr addr;
00258 };
00259
00260 struct mn_config {
00261 struct in_addr mn_home_ip_addr, mn_home_ip_addr_orig;
00262 struct in_addr ha_ip_addr, ha_ip_addr_orig;
00263 struct list alt_ha_ip_addrs;
00264 int use_hadisc;
00265 struct in_addr home_net_addr;
00266 int home_net_addr_plen;
00267 struct in_addr home_net_subnet_bc;
00268 struct in_addr home_net_gateway;
00269 int mndecaps_route_handling;
00270 unsigned char shared_secret[MAXSHAREDSECRETLEN];
00271 int shared_secret_len;
00272 int spi;
00273 int auth_alg;
00274 int replay_meth;
00275 int udp_port;
00276 int enable_fa_decapsulation;
00277 int tunneling_mode;
00278 __u16 mn_default_tunnel_lifetime;
00279 int wlan_ap_poll_interval;
00280 int solicitation_interval;
00281 int syslog_facility;
00282 char mn_api_read_socket_path[MAXFILENAMELEN + 1];
00283 char mn_api_read_socket_group[MAXGROUPNAMELEN + 1];
00284 char mn_api_read_socket_owner[MAXOWNERNAMELEN + 1];
00285 int mn_api_read_socket_permissions;
00286 char mn_api_admin_socket_path[MAXFILENAMELEN + 1];
00287 char mn_api_admin_socket_group[MAXGROUPNAMELEN + 1];
00288 char mn_api_admin_socket_owner[MAXOWNERNAMELEN + 1];
00289 int mn_api_admin_socket_permissions;
00290 int socket_priority;
00291 struct list fa_spi_list;
00292 struct list ignore_iflist;
00293 struct list dev_prio_list;
00294 int enforce_routes;
00295 struct in_addr priv_ha_ip_addr;
00296 __u32 priv_ha;
00297 char mn_nai[MAX_NAI_LEN + 1];
00298 int mn_nai_len;
00299 char ha_nai[MAX_NAI_LEN + 1];
00300 int ha_nai_len;
00301
00302
00303 int use_aaa;
00304 int mn_aaa_spi;
00305 unsigned char mn_aaa_shared_secret[MAXSHAREDSECRETLEN];
00306 int mn_aaa_shared_secret_len;
00307 int mn_aaa_auth_alg;
00308
00309 int mn_aaa_keygen_alg;
00310
00311 time_t mn_ha_key_timestamp;
00312
00313 int mn_ha_key_lifetime;
00314
00315 int allow_home_addr_from_foreign_net;
00316
00317 #ifdef BIND_UDP_SOCKET
00318 struct in_addr bind_addr;
00319 unsigned short bind_port;
00320 #endif
00321 #ifdef INCLUDE_IPAY
00322 struct in_addr ipay_mn_addr;
00323 int ipay_mn_port;
00324 struct in_addr ipay_buyer_addr;
00325 int ipay_buyer_port;
00326 int ipay_fa_port;
00327 #endif
00328 };
00329
00330 struct interface_data {
00331 int s;
00332 int s_adv;
00333 int index;
00334 int handlers_off;
00335 int priority;
00336 char device[IFNAMSIZ];
00337 struct timeval last_solicitation;
00338 };
00339
00340 #ifdef INCLUDE_IPAY
00341 struct nai_data {
00342 int len;
00343 char *nai;
00344 };
00345 #endif
00346
00347 struct mn_data {
00348
00349 int tunnel_up;
00350
00351 int opt_connect;
00352 int registration_socket;
00353
00354 struct interface_data iface[MAX_INTERFACES];
00355 int device_count;
00356
00357 int api_ro_socket, api_rw_socket;
00358 int rtnetlink_socket;
00359 int dev_info_sock;
00360 struct sockaddr_un dev_info_addr;
00361 __u32 registration_id[2];
00362
00363 __u32 last_nonce;
00364 int clock_correction;
00365 struct current_route_info cur_route_info;
00366 struct timeval last_reg_send_time;
00367
00368
00369 struct in_addr local_addr;
00370 struct in_addr co_addr;
00371 struct in_addr force_fa_addr;
00372
00373 __u16 req_lifetime;
00374
00375
00376 unsigned char *session_key;
00377 unsigned int session_key_len;
00378
00379
00380 enum mobile_state state;
00381 struct in_addr fa_addr;
00382
00383 int expire_check;
00384
00385
00386
00387
00388 struct agent_adv_dynamics fa_dynamics_ext;
00389 struct agentadv_data *current_adv;
00390
00391
00392 int ha_error_count;
00393 __u8 last_reply_code;
00394 time_t last_reply_rcvd;
00395 time_t last_request_sent;
00396
00397
00398 struct in_addr tunnel_addr;
00399 int tunnel_mode;
00400 int use_auth_alg;
00401
00402
00403 struct hashtable *agentadv;
00404 char start_default_device[IFNAMSIZ];
00405
00406 char *info_str;
00407 char *warn_str;
00408
00409 int prev_req_replied;
00410
00411 struct fa_nai_ext *last_req_FA_NAI;
00412 unsigned long discarded_msgs;
00413
00414 int HA_reg_retry_time;
00415
00416
00417
00418 struct challenge_ext *last_challenge_ext;
00419 struct timeval last_challenge_time;
00420
00421 int try_to_fix_sec_assoc;
00422
00423
00424
00425
00426 struct in_addr dynamic_home_addr;
00427 char dynamic_home_addr_dev[IFNAMSIZ];
00428
00429 int aaa_rekey;
00430
00431 int home_net_route_set_via_fa;
00432
00433
00434 struct timeval last_scheduled_solicitation;
00435
00436 int policy_bits;
00437
00438 pid_t pcap_capturer;
00439
00440 #ifdef MN_LOCUPD_PROFILER
00441 FILE *profile;
00442 struct timeval last_api;
00443 #endif
00444 #ifdef INCLUDE_IPAY
00445 int ipay_sock;
00446 int ipay_sock_fa;
00447 struct nai_data nai;
00448 int ipay_in_use;
00449 #endif
00450 };
00451
00452
00453
00454 #define POLICY_SET_BIT(bits, bit) (bits |= bit)
00455 #define POLICY_CLR_BIT(bits, bit) (bits &= ~bit)
00456 #define POLICY_BIT(bits, bit) (bits & bit)
00457
00458 #define POLICY(bit) POLICY_BIT(mn.policy_bits, bit)
00459 #define POLICY_SET(bit) POLICY_SET_BIT(mn.policy_bits, bit)
00460 #define POLICY_CLR(bit) POLICY_CLR_BIT(mn.policy_bits, bit)
00461
00462
00463 #define DEFAULT_POLICY_BIT 0
00464 #define EARLY_EXPIRE_BIT 1
00465 #define NEWEST_FA_BIT 2
00466
00467 #define EAGER_SWITCH_BIT 4
00468 #define NEWEST_ADV_BIT 8
00469
00470
00471 #define EARLY_EXPIRE_STR "Early-expire "
00472 #define NEWEST_FA_STR "Newest-FA "
00473 #define EAGER_SWITCH_STR "Eager-switching "
00474 #define NEWEST_ADV_STR "Newest-ADV "
00475
00476
00477 struct policy_vars {
00478 char *name;
00479 int bit;
00480 };
00481
00482
00483
00484
00485
00486 void request_tunnel(int entry, int forced, int check_timer);
00487 void close_for_home(int entry);
00488 void at_home(void);
00489 void passive_find(void);
00490 void find_agent(int entry);
00491 void disconnect(void);
00492 void connected(int type, __u16 lifetime);
00493 int degrade_current_fa_priority(void);
00494
00495
00496 struct fa_spi_entry* get_fa_spi(int spi, struct in_addr addr);
00497 int add_fa_spi(struct fa_spi_entry *spi, int replace_any_spi);
00498 void remove_fa_spi(struct fa_spi_entry *spi);
00499 void send_gratuitous_arp(struct in_addr route_addr,
00500 struct in_addr gratuitous_addr);
00501 #ifdef MN_LOCUPD_PROFILER
00502 void write_profiler(char *msg);
00503 #endif
00504 int check_interfaces(struct interface_data *iface, int iface_n);
00505 int create_registration_socket(void);
00506 int mn_parse_command_line(int argc, char *argv[]);
00507 int restart_tunneling(void);
00508 int start_tunneling(void);
00509 int stop_tunneling(void);
00510 int mn_init(void);
00511 void clean_up(int sig);
00512 void add_fa_host_route(char *dev, struct hashtable *adv_hash,
00513 int ifindex, struct in_addr addr);
00514 void remove_fa_host_routes(int all);
00515 void check_old_tunnel_expiration(void);
00516 int is_coloc_addr_foreign(void);
00517 int device_up(int ifindex);
00518 char *event_type_str(int event_type);
00519 int update_fa_decaps_routes(const char *ifname, int ifindex,
00520 struct in_addr fa_addr,
00521 struct in_addr home_net_addr,
00522 int home_net_addr_plen);
00523 int mn_remove_dynamic_home_addr(void);
00524 int monitor_check_policy(int bit);
00525 int copy_str(char *buffer, int len, int *curr, char *str, char *attr);
00526
00527
00528 int load_mn(struct mn_config *cfg, char *program_name, char *config_file);
00529
00530
00531 void handle_api(int sock, int admin);
00532 void reply_waiting_api(int code, unsigned char *data, int datalen);
00533
00534
00535 int send_registration(int request_type);
00536 int handle_registration(int s);
00537
00538
00539 int adv_ok_fa(struct agentadv_data *adv);
00540 int check_expired_agent_advs(void);
00541
00542
00543 pid_t init_pcap_for_advs(void);
00544
00545 #endif