/* * similar to the hip_request_peer_hit_from_hipd(...) function * */ int hip_request_peer_hit_from_hipd_at_firewall( const struct in6_addr *peer_ip, struct in6_addr *peer_hit, const struct in6_addr *local_hit, in_port_t *src_tcp_port, in_port_t *dst_tcp_port, int *fallback, int *reject){ struct hip_common *msg = NULL; struct in6_addr *hit_recv = NULL; hip_hit_t *ptr = NULL; int err = 0; int ret = 0; *fallback = 1; *reject = 0; HIP_IFE(!(msg = hip_msg_alloc()), -1); HIP_IFEL(hip_build_param_contents(msg, (void *)(local_hit), HIP_PARAM_HIT_LOCAL, sizeof(struct in6_addr)), -1, "build param HIP_PARAM_HIT failed\n"); if (hip_opptcp) { HIP_IFEL(hip_build_param_contents(msg, (void *)(src_tcp_port), HIP_PARAM_SRC_TCP_PORT, sizeof(in_port_t)), -1, "build param HIP_PARAM_SRC_TCP_PORT failed\n"); HIP_IFEL(hip_build_param_contents(msg, (void *)(dst_tcp_port), HIP_PARAM_DST_TCP_PORT, sizeof(in_port_t)), -1, "build param HIP_PARAM_DST_TCP_PORT failed\n"); } HIP_IFEL(hip_build_param_contents(msg, (void *)(peer_ip), HIP_PARAM_IPV6_ADDR_PEER, sizeof(struct in6_addr)), -1, "build param HIP_PARAM_IPV6_ADDR failed\n"); /* build the message header */ HIP_IFEL(hip_build_user_hdr(msg, SO_HIP_GET_PEER_HIT, 0), -1, "build hdr failed\n"); /* this message has to be delivered with the async socket because opportunistic mode responds asynchronously */ HIP_IFEL(hip_send_recv_daemon_info(msg, 1, hip_fw_async_sock), -1, "send msg failed\n"); _HIP_DEBUG("send_recv msg succeed\n"); out_err: if(msg) free(msg); return err; }
/** * Send the necessary data to hipd, so that a tcp packet is sent from there. This was done because it was not possible to send a packet directly from here. * * @param *hdr pointer to the packet that is to be sent. * @param packet_size the size of the packet. * @param ip_version ipv4 or ipv6. * @param addHit whether the local HIT is to be added at the tcp options * @param addOption whether the i1 option is to be added at the tcp options * @return nothing */ int hip_request_send_tcp_packet(void *hdr, int packet_size, int ip_version, int addHit, int addOption){ const struct hip_common *msg = NULL; int err = 0; HIP_DEBUG("\n"); HIP_IFE(!(msg = hip_msg_alloc()), -1); HIP_IFEL(hip_build_param_contents(msg, (void *)hdr, HIP_PARAM_IP_HEADER, packet_size), -1, "build param HIP_PARAM_IP_HEADER failed\n"); HIP_IFEL(hip_build_param_contents(msg, (int *)(&packet_size), HIP_PARAM_PACKET_SIZE, sizeof(int)), -1, "build param HIP_PARAM_PACKET_SIZE failed\n"); HIP_IFEL(hip_build_param_contents(msg, (int *)(&ip_version), HIP_PARAM_TRAFFIC_TYPE, sizeof(int)), -1, "build param HIP_PARAM_TRAFFIC_TYPE failed\n"); HIP_IFEL(hip_build_param_contents(msg, (int *)(&addHit), HIP_PARAM_ADD_HIT, sizeof(int)), -1, "build param HIP_PARAM_ADD_HIT failed\n"); HIP_IFEL(hip_build_param_contents(msg, (int *)(&addOption), HIP_PARAM_ADD_OPTION, sizeof(int)), -1, "build param HIP_PARAM_ADD_OPTION failed\n"); /* build the message header */ HIP_IFEL(hip_build_user_hdr(msg, SO_HIP_OPPTCP_SEND_TCP_PACKET, 0), -1, "build hdr failed\n"); HIP_DUMP_MSG(msg); /* send and receive msg to/from hipd */ HIP_IFEL(hip_send_recv_daemon_info(msg, 1, hip_fw_async_sock), -1, "send_recv msg failed\n"); _HIP_DEBUG("send_recv msg succeed\n"); /* check error value */ //HIP_IFEL(hip_get_msg_err(msg), -1, "Got erroneous message!\n"); out_err: return err; }
/** * No description. */ int hip_query_ip_hit_mapping(struct hip_common *msg){ int err = 0; unsigned int mapping = 0; struct in6_addr *hit = NULL; hip_ha_t *entry = NULL; hit = (struct in6_addr *) hip_get_param_contents(msg, HIP_PARAM_PSEUDO_HIT); HIP_ASSERT(hit_is_opportunistic_hashed_hit(hit)); entry = hip_hadb_try_to_find_by_peer_hit(hit); if(entry) mapping = 1; else mapping = 0; hip_msg_init(msg); HIP_IFEL(hip_build_param_contents(msg, (void *) &mapping, HIP_PARAM_UINT, sizeof(unsigned int)), -1, "build param mapping failed\n"); HIP_IFEL(hip_build_user_hdr(msg, SO_HIP_ANSWER_IP_HIT_MAPPING_QUERY, 0), -1, "build user header failed\n"); out_err: return err; }
/** * Send the ip of a peer to hipd, so that it can: * - unblock the packets that are sent to a particular peer. * - add it to the blacklist database. * * @param peer_ip peer ip. * @return nothing */ int hip_fw_unblock_and_blacklist(const struct in6_addr *peer_ip){ struct hip_common *msg = NULL; int err = 0; HIP_DEBUG("\n"); HIP_IFE(!(msg = hip_msg_alloc()), -1); HIP_IFEL(hip_build_param_contents(msg, (void *)(peer_ip), HIP_PARAM_IPV6_ADDR, sizeof(struct in6_addr)), -1, "build param HIP_PARAM_IPV6_ADDR failed\n"); /* build the message header */ HIP_IFEL(hip_build_user_hdr(msg, SO_HIP_OPPTCP_UNBLOCK_AND_BLACKLIST, 0), -1, "build hdr failed\n"); HIP_DUMP_MSG(msg); /* send and receive msg to/from hipd */ HIP_IFEL(hip_send_recv_daemon_info(msg, 1, hip_fw_async_sock), -1, "send_recv msg failed\n"); _HIP_DEBUG("send_recv msg succeed\n"); /* check error value */ HIP_IFEL(hip_get_msg_err(msg), -1, "Got erroneous message!\n"); out_err: return err; }
/** * Update firewall on host association state. Currently used by the * LSI mode in the firewall. * * @param action HIP_MSG_FW_UPDATE_DB or HIP_MSG_FW_BEX_DONE * @param hit_s optional source HIT * @param hit_r optional destination HIT * * @return zero on success or negative on failure */ int hip_firewall_set_bex_data(int action, struct in6_addr *hit_s, struct in6_addr *hit_r) { struct hip_common *msg = NULL; int err = 0, n = 0, r_is_our; if (!hip_get_firewall_status()) { goto out_err; } /* Makes sure that the hits are sent always in the same order */ r_is_our = hip_hidb_hit_is_our(hit_r); HIP_IFEL(!(msg = malloc(HIP_MAX_PACKET)), -1, "alloc\n"); hip_msg_init(msg); HIP_IFEL(hip_build_user_hdr(msg, action, 0), -1, "Build hdr failed\n"); HIP_IFEL(hip_build_param_contents(msg, r_is_our ? hit_s : hit_r, HIP_PARAM_HIT, sizeof(struct in6_addr)), -1, "build param contents failed\n"); HIP_IFEL(hip_build_param_contents(msg, r_is_our ? hit_r : hit_s, HIP_PARAM_HIT, sizeof(struct in6_addr)), -1, "build param contents failed\n"); n = sendto(hip_firewall_sock_lsi_fd, (char *) msg, hip_get_msg_total_len(msg), 0, (struct sockaddr *) &hip_firewall_addr, sizeof(struct sockaddr_in6)); HIP_IFEL(n < 0, -1, "Send to firewall failed. str errno %s\n", strerror(errno)); HIP_DEBUG("BEX DATA Send to firewall OK.\n"); out_err: free(msg); return err; }
/** * No description. */ int hip_query_opportunistic_mode(struct hip_common *msg){ int err = 0; unsigned int opp_mode = opportunistic_mode; hip_msg_init(msg); HIP_IFEL(hip_build_param_contents(msg, (void *) &opp_mode, HIP_PARAM_UINT, sizeof(unsigned int)), -1, "build param opp_mode failed\n"); HIP_IFEL(hip_build_user_hdr(msg, SO_HIP_ANSWER_OPPORTUNISTIC_MODE_QUERY, 0), -1, "build user header failed\n"); out_err: return err; }
/** creates the anchor element message * * @param hcstore the BEX store * @param use_hash_trees indicates whether hash chains or hash trees are stored * @return the message on success, NULL on error * * @note this will only consider the first hchain item in each shelf, as only * this should be set up for the store containing the hchains for the BEX * @note the created message contains hash_length and anchors for each transform */ static struct hip_common *create_bex_store_update_msg(struct hchain_store *hcstore, const int use_hash_trees) { struct hip_common *msg = NULL; struct esp_prot_tfm *transform = NULL; struct hash_chain *hchain = NULL; struct hash_tree *htree = NULL; unsigned char *anchor = NULL; unsigned j = 0; uint8_t i = 0; int hash_length = 0, num_hchains = 0, err = 0, hash_item_length = 0; HIP_ASSERT(hcstore != NULL); HIP_IFEL(!(msg = malloc(HIP_MAX_PACKET)), -1, "failed to allocate memory\n"); hip_msg_init(msg); HIP_IFEL(hip_build_user_hdr(msg, HIP_MSG_BEX_STORE_UPDATE, 0), -1, "build hdr failed\n"); // first add hash_length and num_hchain for each transform for (i = 1; i <= NUM_TRANSFORMS; i++) { HIP_IFEL(!(transform = esp_prot_resolve_transform(token_transform)), -1, "failed to resolve transform\n"); HIP_IFEL((hash_length = esp_prot_get_hash_length(token_transform)) <= 0, -1, "hash_length <= 0, expecting something bigger\n"); HIP_IFEL((num_hchains = hip_ll_get_size(&hcstore->hchain_shelves[transform->hash_func_id] [transform->hash_length_id]. hchains[DEFAULT_HCHAIN_LENGTH_ID][NUM_BEX_HIERARCHIES - 1])) <= 0, -1, "num_hchains <= 0, expecting something higher\n"); // tell hipd about transform HIP_IFEL(hip_build_param_contents(msg, &token_transform, HIP_PARAM_UINT, sizeof(uint8_t)), -1, "build param contents failed\n"); HIP_DEBUG("added esp_transform: %u\n", token_transform); // add num_hchains for this transform, needed on receiver side HIP_IFEL(hip_build_param_contents(msg, &num_hchains, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("added num_hchains: %i\n", num_hchains); // add the hash_length for this transform, needed on receiver side HIP_IFEL(hip_build_param_contents(msg, &hash_length, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("added hash_length: %i\n", hash_length); } // now add the hchain anchors for (i = 1; i <= NUM_TRANSFORMS; i++) { HIP_IFEL(!(transform = esp_prot_resolve_transform(token_transform)), -1, "failed to resolve transform\n"); HIP_IFEL((hash_length = esp_prot_get_hash_length(token_transform)) <= 0, -1, "hash_length <= 0, expecting something bigger\n"); // ensure correct boundaries HIP_ASSERT(transform->hash_func_id >= 0 && transform->hash_func_id < NUM_HASH_FUNCTIONS); HIP_ASSERT(transform->hash_length_id >= 0 && transform->hash_length_id < NUM_HASH_LENGTHS); // add anchor with this transform for (j = 0; j < hip_ll_get_size(&hcstore->hchain_shelves[transform->hash_func_id] [transform->hash_length_id]. hchains[DEFAULT_HCHAIN_LENGTH_ID][NUM_BEX_HIERARCHIES - 1]); j++) { if (use_hash_trees) { HIP_IFEL(!(htree = hip_ll_get(&hcstore->hchain_shelves[transform->hash_func_id] [transform->hash_length_id].hchains[DEFAULT_HCHAIN_LENGTH_ID][NUM_BEX_HIERARCHIES - 1], j)), -1, "failed to retrieve htree\n"); anchor = htree->root; hash_item_length = htree->num_data_blocks; } else { HIP_IFEL(!(hchain = hip_ll_get(&hcstore->hchain_shelves[transform->hash_func_id] [transform->hash_length_id].hchains[DEFAULT_HCHAIN_LENGTH_ID][NUM_BEX_HIERARCHIES - 1], j)), -1, "failed to retrieve hchain\n"); anchor = hchain_get_anchor(hchain); hash_item_length = hchain->hchain_length; } HIP_IFEL(hip_build_param_contents(msg, anchor, HIP_PARAM_HCHAIN_ANCHOR, hash_length), -1, "build param contents failed\n"); HIP_HEXDUMP("added anchor: ", anchor, hash_length); // also send the hchain/htree length for each item HIP_IFEL(hip_build_param_contents(msg, &hash_item_length, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("added hash_item_length: %i\n", hash_item_length); } } out_err: if (err) { free(msg); msg = NULL; } return msg; }
/** * Notifies the hipd about an anchor change in the hipfw * * @param entry the sadb entry for the outbound direction * @return 0 on success, -1 on error, 1 for inbound sadb entry */ int send_anchor_change_to_hipd(const struct hip_sa_entry *entry) { int err = 0; int hash_length = 0; long i = 0; unsigned char *anchor = NULL; struct hip_common *msg = NULL; struct hash_chain *hchain = NULL; struct hash_tree *htree = NULL; HIP_ASSERT(entry != NULL); HIP_ASSERT(entry->direction == HIP_SPI_DIRECTION_OUT); HIP_IFEL((hash_length = esp_prot_get_hash_length(entry->esp_prot_transform)) <= 0, -1, "error or tried to resolve UNUSED transform\n"); HIP_IFEL(!(msg = malloc(HIP_MAX_PACKET)), -1, "failed to allocate memory\n"); hip_msg_init(msg); HIP_IFEL(hip_build_user_hdr(msg, HIP_MSG_ANCHOR_CHANGE, 0), -1, "build hdr failed\n"); HIP_DEBUG_HIT("src_hit", &entry->inner_src_addr); HIP_IFEL(hip_build_param_contents(msg, &entry->inner_src_addr, HIP_PARAM_HIT, sizeof(struct in6_addr)), -1, "build param contents failed\n"); HIP_DEBUG_HIT("dst_hit", &entry->inner_dst_addr); HIP_IFEL(hip_build_param_contents(msg, &entry->inner_dst_addr, HIP_PARAM_HIT, sizeof(struct in6_addr)), -1, "build param contents failed\n"); HIP_DEBUG("direction: %i\n", entry->direction); HIP_IFEL(hip_build_param_contents(msg, &entry->direction, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("esp_prot_transform: %u\n", entry->esp_prot_transform); HIP_IFEL(hip_build_param_contents(msg, &entry->esp_prot_transform, HIP_PARAM_ESP_PROT_TFM, sizeof(uint8_t)), -1, "build param contents failed\n"); HIP_DEBUG("esp_prot_num_parallel_hchains: %i\n", num_parallel_hchains); HIP_IFEL(hip_build_param_contents(msg, &num_parallel_hchains, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); for (i = 0; i < num_parallel_hchains; i++) { // the anchor change has already occurred on fw-side if (entry->esp_prot_transform == ESP_PROT_TFM_TREE) { htree = entry->active_hash_items[i]; anchor = htree->root; } else { hchain = entry->active_hash_items[i]; anchor = hchain_get_anchor(hchain); } HIP_HEXDUMP("anchor: ", anchor, hash_length); HIP_IFEL(hip_build_param_contents(msg, anchor, HIP_PARAM_HCHAIN_ANCHOR, hash_length), -1, "build param contents failed\n"); } HIP_DUMP_MSG(msg); /* send msg to hipd and receive corresponding reply */ HIP_IFEL(hip_send_recv_daemon_info(msg, 1, hip_fw_sock), -1, "send_recv msg failed\n"); /* check error value */ HIP_IFEL(hip_get_msg_err(msg), -1, "hipd returned error message!\n"); HIP_DEBUG("send_recv msg succeeded\n"); out_err: free(msg); return err; }
/** * Invokes an UPDATE message containing an anchor element as a hook to * next hash structure to be used when the active one depletes * * @param entry the sadb entry for the outbound direction * @param anchors the anchor elements to be sent * @param hash_item_length length of the respective hash item * @param soft_update indicates if HHL-based updates should be used * @param anchor_offset the offset of the anchor element in the link tree * @param link_trees the link trees for the anchor elements, in case of HHL * @return 0 on success, -1 on error */ int send_trigger_update_to_hipd(const struct hip_sa_entry *entry, const unsigned char *anchors[MAX_NUM_PARALLEL_HCHAINS], const int hash_item_length, const int soft_update, const int *anchor_offset, struct hash_tree *link_trees[MAX_NUM_PARALLEL_HCHAINS]) { int err = 0; int i = 0; struct hip_common *msg = NULL; int hash_length = 0; struct hash_chain *hchain = NULL; struct hash_tree *htree = NULL; struct hash_tree *link_tree = NULL; int secret_length = 0; int branch_length = 0; int root_length = 0; const unsigned char *secret = NULL; unsigned char *branch_nodes = NULL; const unsigned char *root = NULL; HIP_ASSERT(entry != NULL); HIP_IFEL((hash_length = esp_prot_get_hash_length(entry->esp_prot_transform)) <= 0, -1, "error or tried to resolve UNUSED transform\n"); HIP_IFEL(!(msg = malloc(HIP_MAX_PACKET)), -1, "failed to allocate memory\n"); hip_msg_init(msg); HIP_IFEL(hip_build_user_hdr(msg, HIP_MSG_TRIGGER_UPDATE, 0), -1, "build hdr failed\n"); HIP_DEBUG_HIT("src_hit", &entry->inner_src_addr); HIP_IFEL(hip_build_param_contents(msg, &entry->inner_src_addr, HIP_PARAM_HIT, sizeof(struct in6_addr)), -1, "build param contents failed\n"); HIP_DEBUG_HIT("dst_hit", &entry->inner_dst_addr); HIP_IFEL(hip_build_param_contents(msg, &entry->inner_dst_addr, HIP_PARAM_HIT, sizeof(struct in6_addr)), -1, "build param contents failed\n"); HIP_DEBUG("esp_prot_transform: %u\n", entry->esp_prot_transform); HIP_IFEL(hip_build_param_contents(msg, &entry->esp_prot_transform, HIP_PARAM_ESP_PROT_TFM, sizeof(uint8_t)), -1, "build param contents failed\n"); // also send the hchain/htree length for all update items HIP_IFEL(hip_build_param_contents(msg, &hash_item_length, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("added hash_item_length: %i\n", hash_item_length); HIP_DEBUG("num_parallel_hchains: %u\n", num_parallel_hchains); HIP_IFEL(hip_build_param_contents(msg, &num_parallel_hchains, HIP_PARAM_INT, sizeof(long)), -1, "build param contents failed\n"); // add update anchors for (i = 0; i < num_parallel_hchains; i++) { HIP_HEXDUMP("anchor: ", anchors[i], hash_length); HIP_IFEL(hip_build_param_contents(msg, anchors[i], HIP_PARAM_HCHAIN_ANCHOR, hash_length), -1, "build param contents failed\n"); } // now transmit root for each next hash item for tree-based updates, if available for (i = 0; i < num_parallel_hchains; i++) { if (entry->esp_prot_transform == ESP_PROT_TFM_TREE) { htree = entry->next_hash_items[i]; link_tree = htree->link_tree; } else { hchain = entry->next_hash_items[i]; link_tree = hchain->link_tree; } if (link_tree) { /* if the next_hchain has got a link_tree, we need its root for * the verification of the next_hchain's elements */ root = htree_get_root(link_tree, &root_length); } // only transmit root length once if (i == 0) { HIP_DEBUG("root_length: %i\n", root_length); HIP_IFEL(hip_build_param_contents(msg, &root_length, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); } if (root) { HIP_HEXDUMP("root: ", root, root_length); HIP_IFEL(hip_build_param_contents(msg, root, HIP_PARAM_ROOT, root_length), -1, "build param contents failed\n"); } } HIP_DEBUG("soft_update: %i\n", soft_update); HIP_IFEL(hip_build_param_contents(msg, &soft_update, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); if (soft_update) { for (i = 0; i < num_parallel_hchains; i++) { secret = htree_get_secret(link_trees[i], anchor_offset[i], &secret_length); HIP_IFEL(!(branch_nodes = htree_get_branch(link_trees[i], anchor_offset[i], NULL, &branch_length)), -1, "failed to get branch nodes\n"); HIP_DEBUG("anchor_offset: %i\n", anchor_offset[i]); HIP_IFEL(hip_build_param_contents(msg, &anchor_offset[i], HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("secret_length: %i\n", secret_length); HIP_IFEL(hip_build_param_contents(msg, &secret_length, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("branch_length: %i\n", branch_length); HIP_IFEL(hip_build_param_contents(msg, &branch_length, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_HEXDUMP("secret: ", secret, secret_length); HIP_IFEL(hip_build_param_contents(msg, secret, HIP_PARAM_SECRET, secret_length), -1, "build param contents failed\n"); HIP_HEXDUMP("branch_nodes: ", branch_nodes, branch_length); HIP_IFEL(hip_build_param_contents(msg, branch_nodes, HIP_PARAM_BRANCH_NODES, branch_length), -1, "build param contents failed\n"); } } HIP_DUMP_MSG(msg); /* send msg to hipd and receive corresponding reply */ HIP_IFEL(hip_send_recv_daemon_info(msg, 1, hip_fw_sock), -1, "send_recv msg failed\n"); /* check error value */ HIP_IFEL(hip_get_msg_err(msg), -1, "hipd returned error message!\n"); HIP_DEBUG("send_recv msg succeeded\n"); out_err: free(msg); free(branch_nodes); return err; }
/** * Sends the preferred transform to hipd implicitely turning on * the esp protection extension there * * @param activate 1 to activate, 0 to deactivate the extension in the hipd * @return 0 on success, -1 on error */ int send_esp_prot_to_hipd(const int activate) { struct hip_common *msg = NULL; int num_transforms = 0; int err = 0, i; uint8_t transform = 0; HIP_ASSERT(activate >= 0); HIP_IFEL(!(msg = malloc(HIP_MAX_PACKET)), -1, "failed to allocate memory\n"); hip_msg_init(msg); HIP_IFEL(hip_build_user_hdr(msg, HIP_MSG_ESP_PROT_TFM, 0), -1, "build hdr failed\n"); if (activate > 0) { /*** activation case ***/ HIP_DEBUG("sending preferred esp prot transforms to hipd...\n"); // all "in use" transforms + UNUSED num_transforms = NUM_TRANSFORMS + 1; HIP_DEBUG("adding activate: %i\n", activate); HIP_IFEL(hip_build_param_contents(msg, &activate, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("adding num_transforms: %i\n", num_transforms); HIP_IFEL(hip_build_param_contents(msg, &num_transforms, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("adding num_parallel_hchains: %i\n", num_parallel_hchains); HIP_IFEL(hip_build_param_contents(msg, &num_parallel_hchains, HIP_PARAM_INT, sizeof(long)), -1, "build param contents failed\n"); for (i = 0; i < num_transforms; i++) { HIP_DEBUG("adding transform %i: %u\n", i + 1, token_transform); HIP_IFEL(hip_build_param_contents(msg, &token_transform, HIP_PARAM_ESP_PROT_TFM, sizeof(uint8_t)), -1, "build param contents failed\n"); } } else { /*** deactivation case ***/ HIP_DEBUG("sending esp prot transform ESP_PROT_TFM_UNUSED to hipd...\n"); // we are only sending ESP_PROT_TFM_UNUSED num_transforms = 1; transform = ESP_PROT_TFM_UNUSED; HIP_DEBUG("adding activate: %i\n", activate); HIP_IFEL(hip_build_param_contents(msg, &activate, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("adding num_transforms: %i\n", num_transforms); HIP_IFEL(hip_build_param_contents(msg, &num_transforms, HIP_PARAM_INT, sizeof(int)), -1, "build param contents failed\n"); HIP_DEBUG("adding num_parallel_hchains: %i\n", num_parallel_hchains); HIP_IFEL(hip_build_param_contents(msg, &num_parallel_hchains, HIP_PARAM_INT, sizeof(long)), -1, "build param contents failed\n"); HIP_DEBUG("adding transform ESP_PROT_TFM_UNUSED: %u\n", transform); HIP_IFEL(hip_build_param_contents(msg, &transform, HIP_PARAM_ESP_PROT_TFM, sizeof(uint8_t)), -1, "build param contents failed\n"); } HIP_DUMP_MSG(msg); /* send msg to hipd and receive corresponding reply */ HIP_IFEL(hip_send_recv_daemon_info(msg, 1, hip_fw_sock), -1, "send_recv msg failed\n"); /* check error value */ HIP_IFEL(hip_get_msg_err(msg), -1, "hipd returned error message!\n"); HIP_DEBUG("send_recv msg succeeded\n"); out_err: free(msg); return err; }
/** Handle message from agent socket. */ int connhipd_handle_msg(struct hip_common *msg, struct sockaddr_un *addr) { /* Variables. */ struct hip_tlv_common *param = NULL, *param2 = NULL; struct hip_common *emsg; hip_hdr_type_t type; HIT_Remote hit, *r; HIT_Local *l; socklen_t alen; struct in6_addr *lhit, *rhit; int err = 0, ret, n, direction, check; char chit[128], *type_s; struct in6_addr hitr ; type = hip_get_msg_type(msg); if (type == SO_HIP_AGENT_PING_REPLY) { HIP_DEBUG("Received ping reply from daemon. Connection to daemon established.\n"); gui_set_info(lang_get("gui-info-000")); hip_agent_connected = 1; } else if (type == SO_HIP_SET_NAT_ON) { gui_update_nat(1); HIP_DEBUG("NAT extensions on.\n"); } else if (type == SO_HIP_SET_NAT_OFF) { gui_update_nat(0); HIP_DEBUG("NAT extensions off.\n"); } else if (type == SO_HIP_DAEMON_QUIT) { HIP_DEBUG("Daemon quit. Waiting daemon to wake up again...\n"); gui_set_info(lang_get("gui-info-001")); hip_agent_connected = 0; } else if (type == SO_HIP_ADD_DB_HI) { HIP_DEBUG("Message received successfully from daemon with type" " HIP_ADD_DB_HI (%d).\n", type); n = 0; while((param = hip_get_next_param(msg, param))) { if (hip_get_param_type(param) == HIP_PARAM_HIT) { lhit = (struct in6_addr *)hip_get_param_contents_direct(param); HIP_HEXDUMP("Adding local HIT:", lhit, 16); print_hit_to_buffer(chit, lhit); hit_db_add_local(chit, lhit); n++; } } } else if (type == SO_HIP_UPDATE_HIU) { n = 0; gui_hiu_clear(); while((param = hip_get_next_param(msg, param))) { /*param2 = hip_get_next_param(msg, param); if (param2 == NULL) break;*/ if (hip_get_param_type(param) == HIP_PARAM_HIT)/* && hip_get_param_type(param2) == HIP_PARAM_HIT)*/ { rhit = (struct in6_addr *)hip_get_param_contents_direct(param); //lhit = hip_get_param_contents_direct(param2); r = hit_db_find(NULL, rhit); if (r) { gui_hiu_add(r); n++; } } } gui_hiu_count(n); } else if (type == HIP_I1 || type == HIP_R1) { NAMECPY(hit.name, ""); URLCPY(hit.url, "<notset>"); URLCPY(hit.port, ""); HIP_DEBUG("Message from daemon, %d bytes.\n", hip_get_msg_total_len(msg)); /* Get original message, which is encapsulated inside received one. */ emsg = (struct hip_common *)hip_get_param_contents(msg, HIP_PARAM_ENCAPS_MSG); HIP_IFEL(!emsg, -1, "Could not get msg parameter!\n"); HIP_HEXDUMP("msg->hits: ", &emsg->hits, 16); HIP_HEXDUMP("msg->hitr: ", &emsg->hitr, 16); /* Find out, which of the HITs in the message is local HIT. */ l = hit_db_find_local(NULL, &emsg->hits); if (!l) { l = hit_db_find_local(NULL, &emsg->hitr); if (l) { memcpy(&hit.hit, &emsg->hits, sizeof(hit.hit)); } HIP_IFEL(!l, -1, "Did not find local HIT for message!\n"); } else { memcpy(&hit.hit, &emsg->hitr, sizeof(hit.hit)); } HIP_DEBUG("Received %s %s from daemon.\n", "incoming", type == HIP_I1 ? "I1" : "R1"); /* Check the remote HIT from database. */ if (l) { memcpy(&hitr,&hit.hit, sizeof(struct in6_addr)); ret = check_hit(&hit, 0); /*Send our hits -- peer hit to daemon*/ if (ret == 1) ret = 0; /*hit already exist in the database and is accepted so no need to send it to daemon*/ else if (ret == 0) connhipd_send_hitdata_to_daemon (msg, &hitr, &hit.g->l->lhit) ; /* Reset local HIT, if outgoing I1. */ /*HIP_HEXDUMP("Old local HIT: ", &msg->hits, 16); HIP_HEXDUMP("New local HIT: ", &hit.g->l->lhit, 16); HIP_HEXDUMP("Old remote HIT: ", &msg->hitr, 16); HIP_HEXDUMP("New remote HIT: ", &hit.hit, 16);*/ } /* If neither HIT in message was local HIT, then drop the packet! */ else { HIP_DEBUG("Failed to find local HIT from database for packet." " Rejecting packet automatically.\n"); HIP_HEXDUMP("msg->hits: ", &msg->hits, 16); HIP_HEXDUMP("msg->hitr: ", &msg->hits, 16); ret = -1; } /* Now either reject or accept the packet, according to previous results. */ if (ret == 0) { HIP_DEBUG("Message accepted, sending back to daemon, %d bytes.\n", hip_get_msg_total_len(msg)); n = hip_send_recv_daemon_info((char *)msg, 1, hip_agent_sock); HIP_IFEL(n < 0, -1, "Could not send message back to daemon" " (%d: %s).\n", errno, strerror(errno)); HIP_DEBUG("Reply sent successfully.\n"); } else if (type == HIP_R1) { HIP_DEBUG("Message rejected.\n"); n = 1; HIP_IFE(hip_build_param_contents(msg, &n, HIP_PARAM_AGENT_REJECT, sizeof(n)), -1); n = hip_send_recv_daemon_info((char *)msg, 1, hip_agent_sock); HIP_IFEL(n < 0, -1, "Could not send message back to daemon" " (%d: %s).\n", errno, strerror(errno)); HIP_DEBUG("Reply sent successfully.\n"); } else { HIP_DEBUG("Message rejected.\n"); } } out_err: // HIP_DEBUG("Message handled.\n"); return (err); }
/** * Build and send a notification about failed connection establishment. * * @param reason the reason why the authentication failed */ int signaling_hipfw_send_connection_failed_ntf(struct hip_common *common, UNUSED struct tuple *tuple, const struct hip_fw_context *ctx, const int reason, const struct signaling_connection *conn) { int err = 0; uint16_t mask = 0; struct hip_common *msg_buf = NULL; struct hip_common *msg_buf2 = NULL; unsigned char *buf; int cert_len = 0; /* Allocate and build message */ HIP_IFEL(!(msg_buf = hip_msg_alloc()), -ENOMEM, "Out of memory while allocation memory for the notify packet\n"); hip_build_network_hdr(msg_buf, HIP_NOTIFY, mask, &our_hit, &common->hits); HIP_IFEL(!(msg_buf2 = hip_msg_alloc()), -ENOMEM, "Out of memory while allocation memory for the notify packet\n"); hip_build_network_hdr(msg_buf2, HIP_NOTIFY, mask, &our_hit, &common->hitr); /* Append certificate */ HIP_IFEL((cert_len = signaling_X509_to_DER(mb_cert, &buf)) < 0, -1, "Could not get DER encoding of certificate\n"); HIP_IFEL(hip_build_param_cert(msg_buf, 0, 1, 1, HIP_CERT_X509V3, buf, cert_len), -1, "Could not build cert parameter\n"); HIP_IFEL(hip_build_param_cert(msg_buf2, 0, 1, 1, HIP_CERT_X509V3, buf, cert_len), -1, "Could not build cert parameter\n"); free(buf); /* Append notification parameter */ signaling_build_param_connection_fail(msg_buf, reason); signaling_build_param_connection_fail(msg_buf2, reason); /* Append connection identifier */ signaling_build_param_signaling_connection(msg_buf, conn); signaling_build_param_signaling_connection(msg_buf2, conn); /* Append hits */ HIP_IFEL(hip_build_param_contents(msg_buf, &common->hitr, HIP_PARAM_HIT, sizeof(hip_hit_t)), -1, "build param contents (dst hit) failed\n"); HIP_IFEL(hip_build_param_contents(msg_buf2, &common->hits, HIP_PARAM_HIT, sizeof(hip_hit_t)), -1, "build param contents (src hit) failed\n"); if (HIP_DEFAULT_HIPFW_ALGO == HIP_HI_ECDSA) { /* Sign the packet */ HIP_IFEL(hip_ecdsa_sign(ecdsa_key, msg_buf), -1, "Could not sign notification for source host \n"); HIP_IFEL(hip_ecdsa_sign(ecdsa_key, msg_buf2), -1, "Could not sign notification for destination host\n"); } else if (HIP_DEFAULT_HIPFW_ALGO == HIP_HI_RSA) { /* Sign the packet */ HIP_IFEL(hip_rsa_sign(rsa_key, msg_buf), -1, "Could not sign notification for source host \n"); HIP_IFEL(hip_rsa_sign(rsa_key, msg_buf2), -1, "Could not sign notification for destination host\n"); } /* Send to source and destination of the connection */ if (send_pkt(NULL, &ctx->src, 10500, 10500, msg_buf)) { HIP_ERROR("Could not notify the source of a connection reject \n"); } free(msg_buf); if (send_pkt(NULL, &ctx->dst, 10500, 10500, msg_buf2)) { HIP_ERROR("Could not notify the destination of a connection reject \n"); } free(msg_buf2); out_err: return err; }