270
270
static int hip_del_host_id(HIP_HASHTABLE *db, hip_hit_t hit)
273
struct local_host_id *id = NULL;
272
struct local_host_id *id = NULL;
275
274
id = hip_get_hostid_entry_by_lhi_and_algo(db, &hit, HIP_ANY_ALGO, -1);
276
275
if (id == NULL) {
277
276
HIP_ERROR("hit not found\n");
282
280
/* Call the handler to execute whatever required after the
414
411
struct local_host_id *id_entry_aux;
415
412
LHASH_NODE *item;
416
413
hip_lsi_t lsi_aux;
417
int err = 0, used_lsi, c, i;
418
415
int len = sizeof(lsi_addresses) / sizeof(*lsi_addresses);
420
417
for (i = 0; i < len; i++) {
604
601
HIP_DEBUG_IN6ADDR("input->hitr = ", &input->hitr);
605
602
if ((err = hip_get_msg_err(input)) != 0) {
606
603
HIP_ERROR("daemon failed (%d)\n", err);
610
607
/* Iterate through all host identities in the input */
619
616
eid_endpoint = (const struct hip_eid_endpoint *) param;
621
HIP_IFEL(!eid_endpoint, -ENOENT, "No host endpoint in input\n");
619
HIP_ERROR("No host endpoint in input\n");
623
623
host_identity = &eid_endpoint->endpoint.id.host_id;
625
HIP_IFEL(hip_private_host_id_to_hit(host_identity, &hit,
626
HIP_HIT_TYPE_HASH100),
627
-EFAULT, "Host id to hit conversion failed\n");
625
if (hip_private_host_id_to_hit(host_identity, &hit, HIP_HIT_TYPE_HASH100)) {
626
HIP_ERROR("Host id to hit conversion failed\n");
629
630
anonymous = (eid_endpoint->endpoint.flags & HIP_ENDPOINT_FLAG_ANON);
634
635
/* Currently only RSA pub is added by default (bug id 592127).
635
636
* Ignore redundant adding in case user wants to enable
636
637
* multiple HITs. */
637
HIP_IFEL(err == -EEXIST, 0, "Ignoring redundant HI\n");
638
if (err == -EEXIST) {
639
HIP_ERROR("Ignoring redundant HI\n");
639
643
/* Adding the pair <HI,LSI> */
641
-EFAULT, "adding of local host identity failed\n");
645
HIP_ERROR("adding of local host identity failed\n");
644
650
IPV4_TO_IPV6_MAP(&lsi, &in6_lsi);
647
653
hip_add_iface_local_route(&in6_lsi);
649
655
/* Adding HITs and LSIs to the interface */
650
HIP_IFEL(hip_add_iface_local_hit(&hit), -1,
651
"Failed to add HIT to the device\n");
652
HIP_IFEL(hip_add_iface_local_hit(&in6_lsi), -1,
653
"Failed to add LSI to the device\n");
656
if (hip_add_iface_local_hit(&hit)) {
657
HIP_ERROR("Failed to add HIT to the device\n");
660
if (hip_add_iface_local_hit(&in6_lsi)) {
661
HIP_ERROR("Failed to add LSI to the device\n");
656
666
HIP_DEBUG("Adding of HIP localhost identities was successful\n");
670
679
const struct in6_addr *hit;
674
683
hit = hip_get_param_contents(input, HIP_PARAM_HIT);
675
HIP_IFEL(!hit, -ENODATA, "no hit\n");
685
HIP_ERROR("no hit\n");
677
689
hip_in6_ntop(hit, buf);
678
690
HIP_INFO("del HIT: %s\n", buf);
680
692
if ((err = hip_del_host_id(HIP_DB_LOCAL_HID, *hit))) {
681
693
HIP_ERROR("deleting of local host identity failed\n");
685
697
/** @todo remove associations from hadb & beetdb by the deleted HI. */
686
698
HIP_DEBUG("Removal of HIP localhost identity was successful\n");
801
808
int hip_hidb_associate_default_hit_lsi(hip_hit_t *default_hit, hip_lsi_t *default_lsi)
804
810
hip_lsi_t aux_lsi;
805
811
struct local_host_id *tmp1;
806
812
struct local_host_id *tmp2;
808
814
//1. Check if default_hit already associated with default_lsi
809
HIP_IFEL((err = hip_hidb_get_lsi_by_hit(default_hit, &aux_lsi)),
811
"Error no lsi associated to hit\n");
815
if (!hip_hidb_get_lsi_by_hit(default_hit, &aux_lsi)) {
816
HIP_ERROR("Error no lsi associated to hit\n");
813
819
if (ipv4_addr_cmp(&aux_lsi, default_lsi)) {
814
HIP_IFEL(!(tmp1 = hip_get_hostid_entry_by_lhi_and_algo(HIP_DB_LOCAL_HID,
818
-1, "Default hit not found in hidb\n");
819
HIP_IFEL(!(tmp2 = hip_hidb_get_entry_by_lsi(HIP_DB_LOCAL_HID, default_lsi)), -1,
820
"Default lsi not found in hidb\n");
820
if (!(tmp1 = hip_get_hostid_entry_by_lhi_and_algo(HIP_DB_LOCAL_HID,
824
HIP_ERROR("Default hit not found in hidb\n");
827
if (!(tmp2 = hip_hidb_get_entry_by_lsi(HIP_DB_LOCAL_HID, default_lsi))) {
828
HIP_ERROR("Default lsi not found in hidb\n");
822
832
memcpy(&tmp2->lsi, &tmp1->lsi, sizeof(tmp1->lsi));
823
833
memcpy(&tmp1->lsi, default_lsi, sizeof(tmp2->lsi));
840
849
int hip_get_host_id_and_priv_key(HIP_HASHTABLE *db, struct in6_addr *hit,
841
850
int algo, struct hip_host_id **host_id, void **key)
843
int err = 0, host_id_len;
844
853
struct local_host_id *entry = NULL;
846
855
entry = hip_get_hostid_entry_by_lhi_and_algo(db, hit, algo, -1);
849
860
host_id_len = hip_get_param_total_len(&entry->host_id);
850
HIP_IFE(host_id_len > HIP_MAX_HOST_ID_LEN, -1);
861
if (host_id_len > HIP_MAX_HOST_ID_LEN) {
852
865
*host_id = malloc(host_id_len);
853
HIP_IFE(!*host_id, -ENOMEM);
854
869
memcpy(*host_id, &entry->host_id, host_id_len);
856
871
*key = entry->private_key;
881
897
int hip_get_default_hit_msg(struct hip_common *msg)
887
HIP_IFE(hip_get_default_hit(&hit), -1);
888
HIP_IFE(hip_get_default_lsi(&lsi), -1);
902
if (hip_get_default_hit(&hit) || hip_get_default_lsi(&lsi)) {
889
906
HIP_DEBUG_HIT("Default hit is ", &hit);
890
907
HIP_DEBUG_LSI("Default lsi is ", &lsi);
891
HIP_IFE(hip_build_param_contents(msg, &hit, HIP_PARAM_HIT, sizeof(hit)),
893
HIP_IFE(hip_build_param_contents(msg, &lsi, HIP_PARAM_LSI, sizeof(lsi)),
909
if (hip_build_param_contents(msg, &hit, HIP_PARAM_HIT, sizeof(hit)) ||
910
hip_build_param_contents(msg, &lsi, HIP_PARAM_LSI, sizeof(lsi))) {
907
923
int hip_get_default_lsi(struct in_addr *lsi)
909
int err = 0, family = AF_INET;
925
int family = AF_INET;
910
926
struct idxmap *idxmap[16] = { 0 };
911
927
struct in6_addr lsi_addr;
912
928
struct in6_addr lsi_aux6;
915
931
set_lsi_prefix(&lsi_tmpl);
916
932
IPV4_TO_IPV6_MAP(&lsi_tmpl, &lsi_addr);
917
HIP_IFEL(hip_iproute_get(&hip_nl_route, &lsi_aux6, &lsi_addr, NULL,
918
NULL, family, idxmap), -1,
919
"Failed to find IP route.\n");
933
if (hip_iproute_get(&hip_nl_route, &lsi_aux6, &lsi_addr, NULL,
934
NULL, family, idxmap)) {
935
HIP_ERROR("Failed to find IP route.\n");
921
939
if (IN6_IS_ADDR_V4MAPPED(&lsi_aux6)) {
922
940
IPV6_TO_IPV4_MAP(&lsi_aux6, lsi);