------------------------------------------------------------ revno: 6282 committer: Xin Gu <eric.nevup@xxxxxxxxx> branch nick: hipl timestamp: Wed 2012-02-15 19:37:10 +0200 message: Preparation for hipd code reuse. Reorganize some global variables and functions in hipd, for the purpose of packing hipd codes into library and reusing them in the future. modified: hipd/esp_prot_hipd_msg.c hipd/hip_socket.c hipd/hip_socket.h hipd/hipd.c hipd/hipd.h hipd/maintenance.c hipd/maintenance.h hipd/nat.c hipd/netdev.c hipd/netdev.h hipd/nsupdate.c hipd/output.c hipd/output.h hipd/user.c hipd/user_ipsec_hipd_msg.c modules/update/hipd/update_builder.c -- lp:hipl https://code.launchpad.net/~hipl-core/hipl/trunk Your team HIPL core team is subscribed to branch lp:hipl. To unsubscribe from this branch go to https://code.launchpad.net/~hipl-core/hipl/trunk/+edit-subscription
=== modified file 'hipd/esp_prot_hipd_msg.c' --- hipd/esp_prot_hipd_msg.c 2011-12-16 13:37:33 +0000 +++ hipd/esp_prot_hipd_msg.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -57,6 +57,10 @@ static uint8_t esp_prot_transforms[MAX_NUM_TRANSFORMS]; +int esp_prot_active = 0; +int esp_prot_num_transforms = 0; +long esp_prot_num_parallel_hchains = 0; + /** * Sends second update message for a public-key-based anchor element update * === modified file 'hipd/hip_socket.c' --- hipd/hip_socket.c 2011-10-25 21:14:16 +0000 +++ hipd/hip_socket.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010, 2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -55,6 +55,30 @@ int (*func_ptr)(struct hip_packet_context *ctx); }; +/* For sending HIP control messages */ +int hip_raw_sock_output_v6 = 0; +int hip_raw_sock_output_v4 = 0; + +/* For receiving HIP control messages */ +int hip_raw_sock_input_v6 = 0; +int hip_raw_sock_input_v4 = 0; + +/** File descriptor of the socket used for sending HIP control packet + * NAT traversal on UDP/IPv4 + */ +int hip_nat_sock_output_udp = 0; + +/** File descriptor of the socket used for receiving HIP control packet + * NAT traversal on UDP/IPv4 + */ +int hip_nat_sock_input_udp = 0; + +int hip_nat_sock_output_udp_v6 = 0; +int hip_nat_sock_input_udp_v6 = 0; + +/* Communication interface to userspace apps (hipconf etc) */ +int hip_user_sock = 0; + /** * List for storage of used sockets */ === modified file 'hipd/hip_socket.h' --- hipd/hip_socket.h 2011-11-25 17:56:24 +0000 +++ hipd/hip_socket.h 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -30,6 +30,15 @@ #include <sys/select.h> #include "lib/core/protodefs.h" +extern int hip_raw_sock_input_v6; +extern int hip_raw_sock_input_v4; +extern int hip_nat_sock_input_udp; +extern int hip_nat_sock_input_udp_v6; + +extern int hip_user_sock; +extern int hip_firewall_sock; +extern struct sockaddr_in6 hip_firewall_addr; + void hip_register_sockets(void); void hip_unregister_sockets(void); === modified file 'hipd/hipd.c' --- hipd/hipd.c 2011-11-25 16:40:40 +0000 +++ hipd/hipd.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -67,41 +67,6 @@ #include "hipd.h" -/** Suppress advertising of none, AF_INET or AF_INET6 address in UPDATEs. - * 0 = none = default, AF_INET, AF_INET6 */ -int suppress_af_family = 0; - -/* For sending HIP control messages */ -int hip_raw_sock_output_v6 = 0; -int hip_raw_sock_output_v4 = 0; - -/* For receiving HIP control messages */ -int hip_raw_sock_input_v6 = 0; -int hip_raw_sock_input_v4 = 0; - -/** File descriptor of the socket used for sending HIP control packet - * NAT traversal on UDP/IPv4 - */ -int hip_nat_sock_output_udp = 0; - -/** File descriptor of the socket used for receiving HIP control packet - * NAT traversal on UDP/IPv4 - */ -int hip_nat_sock_input_udp = 0; - -int hip_nat_sock_output_udp_v6 = 0; -int hip_nat_sock_input_udp_v6 = 0; - -/** Specifies the NAT status of the daemon. This value indicates if the current - * machine is behind a NAT. */ -hip_transform_suite hip_nat_status = 0; - -/* Encrypt host id in I2 */ -int hip_encrypt_i2_hi = 0; - -/* Communication interface to userspace apps (hipconf etc) */ -int hip_user_sock = 0; - /** For receiving netlink IPsec events (acquire, expire, etc) */ struct rtnl_handle hip_nl_ipsec; @@ -109,47 +74,6 @@ * nf_ipsec for this purpose). */ struct rtnl_handle hip_nl_route; -struct sockaddr_in6 hipfw_addr = { 0 }; -static int hipfw_sock = 0; - -/* used to change the transform order see hipconf usage to see the usage - * This is set to AES, 3DES, NULL by default see hipconf transform order for - * more information. - */ -int hip_transform_order = 123; - -/* Tells to the daemon should it build LOCATOR parameters to R1 and I2 */ -int hip_locator_status = HIP_MSG_SET_LOCATOR_OFF; - -/* We are caching the IP addresses of the host here. The reason is that during - * in hip_handle_acquire it is not possible to call getifaddrs (it creates - * a new netlink socket and seems like only one can be open per process). - * Feel free to experiment by porting the required functionality from - * iproute2/ip/ipaddrs.c:ipaddr_list_or_flush(). It would make these global - * variable and most of the functions referencing them unnecessary -miika - */ - -int address_count; -HIP_HASHTABLE *addresses; - -int address_change_time_counter = -1; - -/*Define hip_use_userspace_ipsec variable to indicate whether use - * userspace ipsec or not. If it is 1, hip uses the user space ipsec. - * It will not use if hip_use_userspace_ipsec = 0. Added By Tao Wan - */ -int hip_use_userspace_ipsec = 0; - -int esp_prot_active = 0; -int esp_prot_num_transforms = 0; -long esp_prot_num_parallel_hchains = 0; - -int hip_shotgun_status = HIP_MSG_SHOTGUN_OFF; - -int hip_broadcast_status = HIP_MSG_BROADCAST_OFF; - -int hip_wait_addr_changes_to_stabilize = 1; - /** * print hipd usage instructions on stderr */ @@ -173,32 +97,6 @@ } /** - * send a message to the HIP firewall - * - * @param msg the message to send - * @return zero on success or negative on error - */ -int hip_sendto_firewall(HIPFW const struct hip_common *msg) -{ -#ifdef CONFIG_HIP_FIREWALL - int n = 0; - HIP_DEBUG("CONFIG_HIP_FIREWALL DEFINED AND STATUS IS %d\n", - hipfw_is_alive()); - - n = sendto(hipfw_sock, - msg, - hip_get_msg_total_len(msg), - 0, - (struct sockaddr *) &hipfw_addr, - sizeof(hipfw_addr)); - return n; -#else - HIP_DEBUG("Firewall is disabled.\n"); - return 0; -#endif // CONFIG_HIP_FIREWALL -} - -/** * Parse the command line options * @param argc number of command line parameters * @param argv command line parameters === modified file 'hipd/hipd.h' --- hipd/hipd.h 2011-11-25 17:56:24 +0000 +++ hipd/hipd.h 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -59,50 +59,18 @@ #define HIP_ADDRESS_CHANGE_WAIT_INTERVAL 3 /* seconds */ -extern struct rtnl_handle hip_nl_route; -extern struct rtnl_handle hip_nl_ipsec; extern struct rtnl_handle hip_nl_generic; -extern int hip_raw_sock_input_v6; -extern int hip_raw_sock_input_v4; -extern int hip_nat_sock_input_udp; - -extern int hip_raw_sock_output_v6; -extern int hip_raw_sock_output_v4; -extern int hip_nat_sock_output_udp; - -extern int hip_nat_sock_output_udp_v6; -extern int hip_nat_sock_input_udp_v6; - -extern int address_change_time_counter; - -extern int hip_wait_addr_changes_to_stabilize; - -extern int hip_user_sock; - extern struct sockaddr_in6 hipfw_addr; extern int hit_db_lock; -extern int hip_shotgun_status; - extern int hip_broadcast_status; -extern int hip_encrypt_i2_hi; - -extern hip_transform_suite hip_nat_status; - extern int esp_prot_active; extern int esp_prot_num_transforms; extern long esp_prot_num_parallel_hchains; -extern int hip_locator_status; -extern int hip_transform_order; - -extern int suppress_af_family; -extern int address_count; -extern HIP_HASHTABLE *addresses; - /* For switch userspace / kernel IPsec */ extern int hip_use_userspace_ipsec; === modified file 'hipd/maintenance.c' --- hipd/maintenance.c 2011-12-29 18:52:56 +0000 +++ hipd/maintenance.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -74,6 +74,9 @@ int hipfw_sock_lsi_fd = -1; int hipfw_status = -1; +struct sockaddr_in6 hipfw_addr = { 0 }; +int hipfw_sock = 0; + static float retrans_counter = HIP_RETRANSMIT_INIT; static float precreate_counter = HIP_R1_PRECREATE_INIT; static int force_exit_counter = FORCE_EXIT_COUNTER_START; @@ -387,3 +390,29 @@ free(msg); return err; } + +/** + * send a message to the HIP firewall + * + * @param msg the message to send + * @return zero on success or negative on error + */ +int hip_sendto_firewall(HIPFW const struct hip_common *msg) +{ +#ifdef CONFIG_HIP_FIREWALL + int n = 0; + HIP_DEBUG("CONFIG_HIP_FIREWALL DEFINED AND STATUS IS %d\n", + hipfw_is_alive()); + + n = sendto(hipfw_sock, + msg, + hip_get_msg_total_len(msg), + 0, + (struct sockaddr *) &hipfw_addr, + sizeof(hipfw_addr)); + return n; +#else + HIP_DEBUG("Firewall is disabled.\n"); + return 0; +#endif // CONFIG_HIP_FIREWALL +} === modified file 'hipd/maintenance.h' --- hipd/maintenance.h 2011-11-25 17:56:24 +0000 +++ hipd/maintenance.h 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -33,6 +33,7 @@ extern int hipfw_sock_lsi_fd; extern int hipfw_status; +extern int hipfw_sock; int hip_register_maint_function(int (*maint_function)(void), const uint16_t priority); === modified file 'hipd/nat.c' --- hipd/nat.c 2011-11-07 15:56:02 +0000 +++ hipd/nat.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -64,6 +64,7 @@ #include "lib/core/state.h" #include "hadb.h" #include "hipd.h" +#include "netdev.h" #include "output.h" #include "user.h" #include "nat.h" === modified file 'hipd/netdev.c' --- hipd/netdev.c 2011-12-30 23:20:44 +0000 +++ hipd/netdev.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -89,6 +89,34 @@ /** Maximum lenght of the address family string */ #define FAM_STR_MAX 32 +/** For receiving netlink IPsec events (acquire, expire, etc) */ +struct rtnl_handle hip_nl_ipsec; +/** For getting/setting routes and adding HITs (it was not possible to use + * nf_ipsec for this purpose). */ +struct rtnl_handle hip_nl_route; + +/* We are caching the IP addresses of the host here. The reason is that during + * in hip_handle_acquire it is not possible to call getifaddrs (it creates + * a new netlink socket and seems like only one can be open per process). + * Feel free to experiment by porting the required functionality from + * iproute2/ip/ipaddrs.c:ipaddr_list_or_flush(). It would make these global + * variable and most of the functions referencing them unnecessary -miika + */ +int address_count; +HIP_HASHTABLE *addresses; + +int hip_broadcast_status = HIP_MSG_BROADCAST_OFF; + +int hip_use_userspace_data_packet_mode = 0; +/** Suppress advertising of none, AF_INET or AF_INET6 address in UPDATEs. + * 0 = none = default, AF_INET, AF_INET6 */ +int suppress_af_family = 0; +/** Specifies the NAT status of the daemon. This value indicates if the current + * machine is behind a NAT. */ +hip_transform_suite hip_nat_status = 0; +int address_change_time_counter = -1; +int hip_wait_addr_changes_to_stabilize = 1; + /** * This is the white list. For every interface, which is in our white list, * this array has a fixed size, because there seems to be no need at this @@ -745,12 +773,12 @@ * will be used as a last resort. * @todo move this function to some other file */ -static int netdev_trigger_bex(const hip_hit_t *src_hit_in, - const hip_hit_t *dst_hit_in, - const hip_lsi_t *src_lsi_in, - const hip_lsi_t *dst_lsi_in, - const struct in6_addr *src_addr_in, - const struct in6_addr *dst_addr_in) +int netdev_trigger_bex(const hip_hit_t *src_hit_in, + const hip_hit_t *dst_hit_in, + const hip_lsi_t *src_lsi_in, + const hip_lsi_t *dst_lsi_in, + const struct in6_addr *src_addr_in, + const struct in6_addr *dst_addr_in) { int err = 0, if_index = 0, is_ipv4_locator; int reuse_hadb_local_address = 0, ha_nat_mode = hip_nat_status; === modified file 'hipd/netdev.h' --- hipd/netdev.h 2011-11-25 17:56:24 +0000 +++ hipd/netdev.h 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -36,9 +36,20 @@ #include <netinet/in.h> #include <sys/socket.h> +#include "lib/core/hashtable.h" #include "lib/core/protodefs.h" #include "lib/tool/nlink.h" +extern struct rtnl_handle hip_nl_route; +extern struct rtnl_handle hip_nl_ipsec; +extern int hip_use_userspace_data_packet_mode; +extern int suppress_af_family; +extern int address_count; +extern HIP_HASHTABLE *addresses; +extern hip_transform_suite hip_nat_status; +extern int address_change_time_counter; +extern int hip_wait_addr_changes_to_stabilize; + int hip_devaddr2ifindex(struct in6_addr *addr); int hip_netdev_init_addresses(void); void hip_delete_all_addresses(void); @@ -47,6 +58,12 @@ int hip_remove_iface_all_local_hits(void); int hip_add_iface_local_route(const hip_hit_t *local_hit); int hip_select_source_address(struct in6_addr *src, const struct in6_addr *dst); +int netdev_trigger_bex(const hip_hit_t *src_hit_in, + const hip_hit_t *dst_hit_in, + const hip_lsi_t *src_lsi_in, + const hip_lsi_t *dst_lsi_in, + const struct in6_addr *src_addr_in, + const struct in6_addr *dst_addr_in); int hip_netdev_trigger_bex_msg(const struct hip_common *msg); void hip_add_address_to_list(struct sockaddr *addr, int ifindex, int flags); === modified file 'hipd/nsupdate.c' --- hipd/nsupdate.c 2012-01-25 10:44:48 +0000 +++ hipd/nsupdate.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -57,6 +57,7 @@ #include "config.h" #include "hidb.h" #include "hipd.h" +#include "netdev.h" #include "nsupdate.h" // parameters for nsupdate === modified file 'hipd/output.c' --- hipd/output.c 2012-01-16 22:06:09 +0000 +++ hipd/output.c 2012-02-15 17:37:10 +0000 @@ -70,6 +70,20 @@ #include "output.h" +int hip_shotgun_status = HIP_MSG_SHOTGUN_OFF; + +/* Encrypt host id in I2 */ +int hip_encrypt_i2_hi = 0; + +/* used to change the transform order see hipconf usage to see the usage + * This is set to AES, 3DES, NULL by default see hipconf transform order for + * more information. + */ +int hip_transform_order = 123; + +/* Tells to the daemon should it build LOCATOR parameters to R1 and I2 */ +int hip_locator_status = HIP_MSG_SET_LOCATOR_OFF; + /* Set to 1 if you want to simulate lost output packet */ #define HIP_SIMULATE_PACKET_LOSS 1 /* Packet loss probability in percents */ === modified file 'hipd/output.h' --- hipd/output.h 2011-11-25 17:56:24 +0000 +++ hipd/output.h 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2011 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -35,6 +35,17 @@ extern int hip_raw_sock_v6; extern int hip_raw_sock_v4; +extern int hip_raw_sock_output_v6; +extern int hip_raw_sock_output_v4; +extern int hip_nat_sock_output_udp; +extern int hip_nat_sock_output_udp_v6; + +extern int is_active_mhaddr; +extern int is_hard_handover; +extern int hip_shotgun_status; +extern int hip_encrypt_i2_hi; +extern int hip_locator_status; +extern int hip_transform_order; int hip_create_r1(struct hip_common *const msg, const struct in6_addr *const src_hit, === modified file 'hipd/user.c' --- hipd/user.c 2012-01-14 14:20:17 +0000 +++ hipd/user.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -72,6 +72,7 @@ #include "esp_prot_hipd_msg.h" #include "hadb.h" #include "hidb.h" +#include "hip_socket.h" #include "hipd.h" #include "hiprelay.h" #include "hit_to_ip.h" === modified file 'hipd/user_ipsec_hipd_msg.c' --- hipd/user_ipsec_hipd_msg.c 2011-08-15 14:11:56 +0000 +++ hipd/user_ipsec_hipd_msg.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -47,6 +47,12 @@ #include "user_ipsec_hipd_msg.h" +/* Define hip_use_userspace_ipsec variable to indicate whether use + * userspace ipsec or not. If it is 1, hip uses the user space ipsec. + * It will not use if hip_use_userspace_ipsec = 0. Added By Tao Wan + */ +int hip_use_userspace_ipsec = 0; + /** * handles a userspace ipsec activation message sent by the fw * === modified file 'modules/update/hipd/update_builder.c' --- modules/update/hipd/update_builder.c 2012-01-14 14:20:17 +0000 +++ modules/update/hipd/update_builder.c 2012-02-15 17:37:10 +0000 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010 Aalto University and RWTH Aachen University. + * Copyright (c) 2010-2012 Aalto University and RWTH Aachen University. * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation @@ -35,7 +35,7 @@ #include <errno.h> #include "hipd/hadb.h" -#include "hipd/hipd.h" +#include "hipd/netdev.h" #include "lib/core/builder.h" #include "lib/core/ife.h" #include "lib/core/list.h"