mn.h

Go to the documentation of this file.
00001 /* $Id: mn.h,v 1.95 2001/09/30 09:00:48 jm Exp $
00002  * Header files for Mobile Node module
00003  *
00004  * Dynamic hierarchial IP tunnel
00005  * Copyright (C) 1998-2001, Dynamics group
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License version 2 as
00009  * published by the Free Software Foundation. See README and COPYING for
00010  * more details.
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 /* linux/wireless.h does not like net/if.h and wireless.h is not available
00028  * from glibc :( */
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 /* defines */
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 /* Comment this out, if you do not want to mess your
00062  * routing table during testing. (for example remotely) */
00063 #define MN_ENABLE_TUNNELING
00064 
00065 /* Comment out for running tests without message validation */
00066 #define MN_ENABLE_VALIDATION
00067 
00068 /* minimum time that must pass between two registration requests/solicitations
00069  * in microseconds (default: 1000000 usec = 1 sec)
00070  * Location update signal with API call clears the timers, so this does not
00071  * limit the locupd frequency */
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 /* Maximum message length */
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 /* general timer */
00091 #define TIMER_GEN                           0
00092 /* tunnel lifetime */
00093 #define TIMER_LIFETIME                      1
00094 /* lifetime of last advertisement */
00095 #define TIMER_ADV                           2
00096 /* time when last registration request was sent */
00097 #define TIMER_REQUEST                       3
00098 /* timer for next reregistration */
00099 #define TIMER_REREG                         4
00100 /* timer for wireless LAN AP handoff detection */
00101 #define TIMER_WLAN_AP_POLL                  5
00102 /* timer for agent solicitation sending */
00103 #define TIMER_SOLICITATION                  6
00104 #define TIMER_COUNT                         7
00105 
00106 
00107 /* registration request types */
00108 #define REG_DISC       0
00109 #define REG_CONNECT    1
00110 #define REG_REREG      2
00111 
00112 /* connect types:
00113 *   CON_HA: Connection approved by Home Agent
00114 *   CON_FA: Connection approved by Foreign Agent */
00115 #define CON_HA 0
00116 #define CON_FA 1
00117 
00118 /* state entry types */
00119 #define STATE_INIT    0
00120 #define STATE_TIMEOUT 1
00121 
00122 /* number of seconds that the tunnel to the old FA is kept alive */
00123 #define OLD_TUNNEL_EXTRA_TIME 3
00124 
00125 /* Registration retry interval in seconds
00126  * Min interval is used as initial reply interval, but for each
00127  * successive retry, the timeout is doubled until
00128  * max time is reached */
00129 #define MIN_REGISTRATION_TIME  1
00130 #define MAX_REGISTRATION_TIME  32
00131 
00132 #define DEREGISTRATION_INTERVAL 8
00133 
00134 /* 10% priority degrade when first registration request fails */
00135 #define DEFAULT_PRIO_DEGRADE_INITIAL 10    
00136 
00137 /* Additional degrades: multiply last one. 
00138    E.g. 10%, 20%, 40%, 80%, 100% */
00139 #define DEFAULT_PRIO_DEGRADE_FACTOR 2 
00140 
00141 /* When agent advertisements are heard, degrade the priority
00142    degradation value by 10% (0.9) */
00143 #define DEFAULT_PRIO_DEGRADE_DEGRADE 0.9  
00144 
00145 /* Additional degrade percentage if mobility agent does not reply to a periodic
00146  * solicitation (add this to adv->prio_degrade_percent) */
00147 #define SOLICITATION_PRIO_DEGRADE 10
00148 
00149 /* Number of microseconds to wait for agent advertisement before considering
00150  * mobility agent not to have replied to agent solicitation */
00151 #define MAX_AGENTSOL_REPLY_WAIT 1500000
00152 
00153 /* Solicitation intervals in seconds (see RFC 2002, sec. 2.4) */
00154 #define SOLICITATION_INTERVALS {1, 1, 1, 2, 4, 8, 16, 32, 64}
00155 
00156 /* Randomized delay added to solicitation interval in usecs
00157  * (0 .. MAX_RANDOM_SOLICITATION_DELAY usecs is added to the delay)
00158  */
00159 #define MAX_RANDOM_SOLICITATION_DELAY 500000
00160 
00161 /* Normal reregistration time in seconds before tunnel lifetime ends */
00162 #define NORMAL_REREGISTRATION_TIME  32
00163 
00164 /* Re-register via AAA MN_AAA_REG_TIME seconds before expiration of dynamic
00165  * security association */
00166 #define MN_AAA_REG_TIME 15
00167 
00168 /* Max number of deregistration messages sent to HA in state Close for home */
00169 #define MAX_DEREGISTRATION_TO_HA 5
00170 
00171 /* Minimum allowed lifetime (in seconds) */
00172 #define MIN_ALLOWED_LIFETIME  1
00173 
00174 /* Maximum errors allowed during registration with HA */
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 /* The process id of the daemon is saved here to make it easier to
00182    kill the correct daemon when necessary. */
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 /* Uncomment this to bind UDP socket to a configurable
00196  * (dynmnd.conf: BindAddress, BindPort) address.
00197  * This can be used for testing several MNs on one machine with multiple alias
00198  * addressed. */
00199 /* #define BIND_UDP_SOCKET */
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 /* States */
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 /* structures */
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; /* 0:  static security association,
00239                          * != 0: timestamp of dynamic security association */
00240         unsigned int lifetime; /* for dynamic security associations:
00241                                 * lifetime of the key in seconds */
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; /* from home_net_addr/plen */
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; /* interval in usec or -1 = disabled */
00280         int solicitation_interval; /* interval in usec or -1 = disabled */
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         /* RFC 3012 */
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; /* timestamp for MN-HA key generation
00312                                      * using material from AAA */
00313         int mn_ha_key_lifetime; /* lifetime for MN-HA key generated by AAA,
00314                                  * 0 = infinite */
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; /* socket */
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         /* Is tunnel up? */
00349         int tunnel_up; /* if tunneling is working, i.e. if connection is
00350                           working. Mainly for get_mobile_status */
00351         int opt_connect; /* 1 = try to connect immediately */
00352         int registration_socket; /* Socket for registration requests and
00353                                   * replies */
00354         struct interface_data iface[MAX_INTERFACES];
00355         int device_count; /* number of available interfaces in the iface list
00356                            */
00357         int api_ro_socket, api_rw_socket; /* sockets for api calls */
00358         int rtnetlink_socket; /* socket for rtnetlink monitoring */
00359         int dev_info_sock; /* socket for device information query daemon */
00360         struct sockaddr_un dev_info_addr;
00361         __u32 registration_id[2]; /* id field of last sent registration request
00362                                    */
00363         __u32 last_nonce; /* last nonce received in a reply */
00364         int clock_correction; /* time difference to home agent's clock */
00365         struct current_route_info cur_route_info;
00366         struct timeval last_reg_send_time; /* time of last registration
00367                                             * sending */
00368 
00369         struct in_addr local_addr; /* address of mobile in connected network */
00370         struct in_addr co_addr; /* current care-of address of the MN */
00371         struct in_addr force_fa_addr; /* only accept this FA if != 0.0.0.0 */
00372 
00373         __u16 req_lifetime; /* lifetime to be requested */
00374 
00375 
00376         unsigned char *session_key; /* session key */
00377         unsigned int session_key_len; /* length of session key */
00378 
00379         /* State variables */
00380         enum mobile_state state; /* current state */
00381         struct in_addr fa_addr; /* address of current mobility agent (FA/HA),
00382                                  * for signalling, routing, tunneling */
00383         int expire_check; /* is it ok to monitor agent adv. expiring;
00384                            * set when received accepted registration 
00385                            * in handle_reg_accept(), and used in 
00386                            * get_next_timeout() */
00387         /* the data of the Dynamics extension, if it was sent */
00388         struct agent_adv_dynamics fa_dynamics_ext;
00389         struct agentadv_data *current_adv; /* advertisement matching the lowest
00390                                               mobilty agent we are currently 
00391                                               using */
00392         int ha_error_count; /* errors during registration with ha */
00393         __u8 last_reply_code;
00394         time_t last_reply_rcvd;
00395         time_t last_request_sent;
00396 
00397         /* tunneling variables */
00398         struct in_addr tunnel_addr; /* address used in tunnel FA endpoint */
00399         int tunnel_mode; /* API_TUNNEL_{NONE,FULL,TRIANGLE,FULL_HA} */
00400         int use_auth_alg; /* currently used authentication algorithm,
00401                            * same as config.auth_alg if HA is using standard
00402                            * method */
00403         struct hashtable *agentadv;
00404         char start_default_device[IFNAMSIZ]; /* device that was used when the
00405                                               * MN daemon was started */
00406         char *info_str; /* information text to the user */
00407         char *warn_str; /* warning text to the user */
00408 
00409         int prev_req_replied; /* whether the MN has received a reply to its
00410                                * previous request */
00411         struct fa_nai_ext *last_req_FA_NAI;
00412         unsigned long discarded_msgs;
00413 
00414         int HA_reg_retry_time; /* like adv->reg_retry_time but for direct
00415                                 * HA registrations (that do not usually
00416                                 * have received an agentadv) */
00417 
00418         struct challenge_ext *last_challenge_ext;
00419         struct timeval last_challenge_time;
00420 
00421         int try_to_fix_sec_assoc; /* whether MN should try to fix a dynamic
00422                                    * security association by reregistering */
00423 
00424         /* dynamic home address added by Dynamics MN (or 0 if not used);
00425          * this address will be removed when the binding expires/is removed */
00426         struct in_addr dynamic_home_addr;
00427         char dynamic_home_addr_dev[IFNAMSIZ];
00428 
00429         int aaa_rekey; /* 1 = try to rekey AAA-based security assoc. */
00430 
00431         int home_net_route_set_via_fa; /* whether home net is set via FA;
00432                                         * currently used only with Windows */
00433 
00434         struct timeval last_scheduled_solicitation;
00435 
00436         int policy_bits; /* Handoff policy */
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 /* policy bit field operations */
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 /* POLICIES: */
00463 #define DEFAULT_POLICY_BIT   0 /* average and treshold */
00464 #define EARLY_EXPIRE_BIT     1 /* use own aging for agent advertisements */
00465 #define NEWEST_FA_BIT        2 /* Use FA with newest agent advert. 
00466                                   (infra mode) */
00467 #define EAGER_SWITCH_BIT     4 /* no average nor treshold */
00468 #define NEWEST_ADV_BIT       8 /* use newest agent adv.; like NEWEST_FA, but
00469                                 * without limiting threshold etc. */
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 /* Policy variables */
00477 struct policy_vars {
00478         char *name; /* name of the policy */
00479         int bit;    /* the bit used for this policy in policy_bits */
00480 };
00481 
00482 
00483 /* function prototypes */
00484 
00485 /* mn.c */
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 /* mn_util.c */
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 /* mn_config.c */
00528 int load_mn(struct mn_config *cfg, char *program_name, char *config_file);
00529 
00530 /* mn_api.c */
00531 void handle_api(int sock, int admin);
00532 void reply_waiting_api(int code, unsigned char *data, int datalen);
00533 
00534 /* mn_reg.c */
00535 int send_registration(int request_type);
00536 int handle_registration(int s);
00537 
00538 /* mn_agentadv.c */
00539 int adv_ok_fa(struct agentadv_data *adv);
00540 int check_expired_agent_advs(void);
00541 
00542 /* win_adv_capture.c */
00543 pid_t init_pcap_for_advs(void);
00544 
00545 #endif /* MN_H */

Generated on Tue Jan 15 08:50:43 2008 for Virtual foreign agent generator version 0.1 by  doxygen 1.5.1