43
42
#include <stdint.h>
44
43
#include <string.h>
46
#include "lib/core/builder.h"
47
#include "lib/core/ife.h"
48
#include "lib/core/linkedlist.h"
49
#include "lib/core/prefix.h"
50
#include "lib/core/protodefs.h"
45
#include "libcore/builder.h"
46
#include "libcore/ife.h"
47
#include "libcore/linkedlist.h"
48
#include "libcore/prefix.h"
49
#include "libcore/protodefs.h"
106
106
* Deletes one expired pending request. Deletes the first exipired pending
107
107
* request from the pending request linked list @c pending_requests.
109
static int hip_del_pending_request_by_expiration(void)
109
static int del_pending_request_by_expiration(void)
112
112
time_t now = time(NULL);
113
113
const struct hip_ll_node *iter = NULL;
114
114
struct hip_pending_request *request = NULL;
116
/* See hip_del_pending_request() for a comment. */
117
116
while ((iter = hip_ll_iterate(&pending_requests, iter)) != NULL) {
118
117
request = iter->ptr;
119
118
if (now - request->created > HIP_PENDING_REQUEST_LIFETIME) {
120
HIP_DEBUG("Deleting and freeing a pending request by " \
119
HIP_DEBUG("Deleting and freeing a pending request by "
121
120
"expiration (%u seconds) at index %u.\n",
122
121
now - request->created, idx);
123
122
hip_ll_del(&pending_requests, idx, free);
237
* Deletes a pending request. Deletes a pending request identified by the host
238
* association @c entry from the linked list @c pending_requests.
240
* @param entry a pointer to the host association to which the pending request
241
* to be deleted is bound.
242
* @return zero if the pending request was succesfully deleted, -1
245
int hip_del_pending_request(struct hip_hadb_state *entry)
248
const struct hip_ll_node *iter = NULL;
250
/* Iterate through the linked list. The iterator itself can't be used
251
* for deleting nodes from the list. Therefore, we just get the index of
252
* the element to be deleted using the iterator and then call
253
* hip_ll_del() to do the actual deletion. */
254
while ((iter = hip_ll_iterate(&pending_requests, iter)) != NULL) {
255
if (((struct hip_pending_request *) (iter->ptr))->entry == entry) {
256
HIP_DEBUG("Deleting and freeing a pending request at " \
258
hip_ll_del(&pending_requests, idx, free);
268
236
* Deletes a pending request of given type. Deletes a pending request identified
269
237
* by the host association @c entry and matching the given type @c reg_type from
270
238
* the linked list @c pending_requests.
272
240
* @param entry a pointer to a host association to which the pending request
273
241
* to be deleted is bound.
274
242
* @param reg_type the type of the pending request to delete.
275
* @return zero if the pending request was succesfully deleted, -1
243
* @return zero if the pending request was successfully deleted, -1
278
static int hip_del_pending_request_by_type(struct hip_hadb_state *entry,
246
static int del_pending_request_by_type(struct hip_hadb_state *entry,
282
250
const struct hip_ll_node *iter = NULL;
283
251
struct hip_pending_request *request = NULL;
285
/* See hip_del_pending_request() for a comment. */
286
253
while ((iter = hip_ll_iterate(&pending_requests, iter)) != NULL) {
287
254
request = iter->ptr;
288
255
if (request->entry == entry && request->reg_type == reg_type) {
289
HIP_DEBUG("Deleting and freeing a pending request by " \
256
HIP_DEBUG("Deleting and freeing a pending request by "
290
257
"type at index %u.\n", idx);
291
258
hip_ll_del(&pending_requests, idx, free);
329
296
* Make sure that the target buffer @c requests has room for at least as many
330
297
* pending requests that the host association @c entry has currently. You can
331
* have this number by calling hip_get_pending_request_count().
298
* have this number by calling get_pending_request_count().
333
300
* @param entry a pointer to a host association whose pending requests are
335
302
* @param requests a target buffer for the pending requests.
336
303
* @return -1 if @c requests is NULL or if no pending requests were
337
304
* found, zero otherwise.
338
* @see hip_get_pending_request_count().
305
* @see get_pending_request_count().
340
static int hip_get_pending_requests(struct hip_hadb_state *entry,
341
struct hip_pending_request *requests[])
307
static int get_pending_requests(struct hip_hadb_state *entry,
308
struct hip_pending_request *requests[])
343
310
const struct hip_ll_node *iter = 0;
344
311
int request_count = 0;
386
353
* Adds new registrations to services at the server. This function tries to add
387
354
* all new services listed and indentified by @c types. This is server side
388
355
* addition, meaning that the server calls this function to add entries
389
* to its served client list. After the function finishes, succesful registrations
390
* are listed in @c accepted_requests and unsuccesful registrations in
356
* to its served client list. After the function finishes, successful registrations
357
* are listed in @c accepted_requests and unsuccessful registrations in
391
358
* @c refused_requests.
393
360
* Make sure that you have allocated memory to @c accepted_requests,
416
383
* @param refused_count a target buffer that will store the number of Reg
417
384
* Types in @c refused_requests.
418
385
* @return zero on success, -1 otherwise.
419
* @see hip_add_registration_client().
386
* @see add_registration_client().
421
static int hip_add_registration_server(struct hip_hadb_state *entry,
423
const uint8_t *reg_types,
425
uint8_t accepted_requests[],
426
uint8_t accepted_lifetimes[],
427
int *accepted_count, uint8_t refused_requests[],
428
uint8_t failure_types[], int *refused_count)
388
static int add_registration_server(struct hip_hadb_state *entry,
390
const uint8_t *reg_types,
392
uint8_t accepted_requests[],
393
uint8_t accepted_lifetimes[],
394
int *accepted_count, uint8_t refused_requests[],
395
uint8_t failure_types[], int *refused_count)
430
397
int err = 0, i = 0;
431
398
struct hip_relrec dummy, *fetch_record = NULL, *new_record = NULL;
524
491
refused_requests[*refused_count] = reg_types[i];
525
492
failure_types[*refused_count] = HIP_REG_TRANSIENT_CONDITIONS;
526
493
(*refused_count)++;
527
HIP_ERROR("Unable to store new relay " \
528
"record. Registration " \
494
HIP_ERROR("Unable to store new relay record. Registration refused.\n");
535
500
HIP_DEBUG("Client is trying to register to an "
536
"unsupported service.\nRegistration " \
501
"unsupported service.\nRegistration refused.\n");
538
502
refused_requests[*refused_count] = reg_types[i];
539
503
failure_types[*refused_count] =
540
504
HIP_REG_TYPE_UNAVAILABLE;
551
515
* Cancels registrations to services at the server. This function tries to
552
516
* cancel all services listed and indentified by @c types. This is server side
553
517
* cancellation, meaning that the server calls this function to remove entries
554
* from its served client list. After the function finishes, succesful
555
* cancellations are listed in @c accepted_requests and unsuccesful requests
518
* from its served client list. After the function finishes, successful
519
* cancellations are listed in @c accepted_requests and unsuccessful requests
556
520
* in @c refused_requests.
558
522
* Make sure that you have allocated memory to both @c accepted_requests and
572
536
* Types in @c refused_requests.
573
537
* @param failure_types the failure types
574
538
* @return zero on success, -1 otherwise.
575
* @see hip_del_registration_client().
539
* @see del_registration_client().
577
static int hip_del_registration_server(struct hip_hadb_state *entry,
578
const uint8_t *reg_types,
580
uint8_t accepted_requests[],
582
uint8_t refused_requests[],
583
uint8_t failure_types[],
541
static int del_registration_server(struct hip_hadb_state *entry,
542
const uint8_t *reg_types,
544
uint8_t accepted_requests[],
546
uint8_t refused_requests[],
547
uint8_t failure_types[],
586
550
int err = 0, i = 0;
587
551
struct hip_relrec dummy, *fetch_record = NULL;
601
565
/* RVS and relay deletions are identical except the
602
566
* relay record type. */
603
567
if (reg_types[i] == HIP_SERVICE_RENDEZVOUS) {
604
HIP_DEBUG("Client is cancelling registration " \
568
HIP_DEBUG("Client is cancelling registration "
605
569
"to rendezvous service.\n");
606
570
type_to_delete = HIP_RVSRELAY;
607
571
} else if (reg_types[i] == HIP_SERVICE_RELAY) {
608
HIP_DEBUG("Client is cancelling registration " \
572
HIP_DEBUG("Client is cancelling registration "
609
573
"to relay service.\n");
610
574
type_to_delete = HIP_RELAY;
612
HIP_DEBUG("Client is cancelling registration " \
576
HIP_DEBUG("Client is cancelling registration "
613
577
"to full relay service.\n");
614
578
type_to_delete = HIP_FULLRELAY;
629
593
HIP_REG_TYPE_UNAVAILABLE;
630
594
(*refused_count)++;
631
595
} else if (fetch_record == NULL) {
632
HIP_DEBUG("There is no relay record to " \
596
HIP_DEBUG("There is no relay record to cancel.\n");
634
597
refused_requests[*refused_count] = reg_types[i];
635
598
failure_types[*refused_count] =
636
599
HIP_REG_TYPE_UNAVAILABLE;
637
600
(*refused_count)++;
638
601
} else if (fetch_record->type != type_to_delete) {
639
HIP_DEBUG("The relay record to be cancelled " \
640
"is of wrong type.\n");
602
HIP_DEBUG("The relay record to be cancelled is of wrong type.\n");
641
603
refused_requests[*refused_count] = reg_types[i];
642
604
failure_types[*refused_count] =
643
605
HIP_REG_TYPE_UNAVAILABLE;
698
660
* @param reg_types a pointer to Reg Types found in REG_REQUEST.
699
661
* @param type_count number of Reg Types in @c reg_types.
700
662
* @return zero on success, -1 otherwise.
701
* @see hip_add_registration_server().
663
* @see add_registration_server().
703
static int hip_add_registration_client(struct hip_hadb_state *entry, uint8_t lifetime,
704
const uint8_t *reg_types,
665
static int add_registration_client(struct hip_hadb_state *entry, uint8_t lifetime,
666
const uint8_t *reg_types,
708
670
time_t seconds = 0;
718
680
switch (reg_types[i]) {
719
681
case HIP_SERVICE_RENDEZVOUS:
721
HIP_DEBUG("The server has granted us rendezvous " \
683
HIP_DEBUG("The server has granted us rendezvous "
722
684
"service for %u seconds (lifetime 0x%x.)\n",
723
685
seconds, lifetime);
724
686
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_RVS);
725
687
hip_hadb_set_peer_controls(entry, HIP_HA_CTRL_PEER_GRANTED_RVS);
726
hip_del_pending_request_by_type(entry, HIP_SERVICE_RENDEZVOUS);
688
del_pending_request_by_type(entry, HIP_SERVICE_RENDEZVOUS);
729
691
case HIP_SERVICE_RELAY:
731
HIP_DEBUG("The server has granted us relay " \
693
HIP_DEBUG("The server has granted us relay "
732
694
"service for %u seconds (lifetime 0x%x.)\n",
733
695
seconds, lifetime);
734
696
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_RELAY);
735
697
hip_hadb_set_peer_controls(entry, HIP_HA_CTRL_PEER_GRANTED_RELAY);
736
hip_del_pending_request_by_type(entry, HIP_SERVICE_RELAY);
698
del_pending_request_by_type(entry, HIP_SERVICE_RELAY);
739
701
case HIP_SERVICE_FULLRELAY:
741
HIP_DEBUG("The server has granted us full relay " \
703
HIP_DEBUG("The server has granted us full relay "
742
704
"service for %u seconds (lifetime 0x%x.)\n",
743
705
seconds, lifetime);
744
706
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_FULLRELAY);
745
707
hip_hadb_set_peer_controls(entry, HIP_HA_CTRL_PEER_GRANTED_FULLRELAY);
746
hip_del_pending_request_by_type(entry, HIP_SERVICE_FULLRELAY);
708
del_pending_request_by_type(entry, HIP_SERVICE_FULLRELAY);
747
709
/* Delete SAs with relay server to
748
710
* avoid problems with ESP relay*/
749
711
entry->disable_sas = 1;
756
HIP_DEBUG("The server has granted us an unknown " \
718
HIP_DEBUG("The server has granted us an unknown "
757
719
"service for %u seconds (lifetime 0x%x.)\n",
758
720
seconds, lifetime);
759
721
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_UNSUP);
760
722
hip_hadb_set_peer_controls(entry, HIP_HA_CTRL_PEER_GRANTED_UNSUP);
761
hip_del_pending_request_by_type(entry, reg_types[i]);
723
del_pending_request_by_type(entry, reg_types[i]);
777
739
* @param reg_types a pointer to Reg Types found in REG_REQUEST.
778
740
* @param type_count number of Reg Types in @c reg_types.
779
741
* @return zero on success, -1 otherwise.
780
* @see hip_del_registration_client().
742
* @see del_registration_client().
782
static int hip_del_registration_client(struct hip_hadb_state *entry,
783
const uint8_t *reg_types,
744
static int del_registration_client(struct hip_hadb_state *entry,
745
const uint8_t *reg_types,
792
754
switch (reg_types[i]) {
793
755
case HIP_SERVICE_RENDEZVOUS:
795
HIP_DEBUG("The server has cancelled our rendezvous " \
757
HIP_DEBUG("The server has cancelled our rendezvous service.\n");
797
758
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_RVS);
798
hip_del_pending_request_by_type(entry, HIP_SERVICE_RENDEZVOUS);
759
del_pending_request_by_type(entry, HIP_SERVICE_RENDEZVOUS);
801
762
case HIP_SERVICE_RELAY:
803
HIP_DEBUG("The server has cancelled our relay " \
764
HIP_DEBUG("The server has cancelled our relay service.\n");
805
765
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_RELAY);
806
hip_del_pending_request_by_type(entry, HIP_SERVICE_RELAY);
766
del_pending_request_by_type(entry, HIP_SERVICE_RELAY);
810
770
case HIP_SERVICE_FULLRELAY:
812
HIP_DEBUG("The server has cancelled our full relay " \
772
HIP_DEBUG("The server has cancelled our full relay service.\n");
814
773
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_FULLRELAY);
815
hip_del_pending_request_by_type(entry, HIP_SERVICE_FULLRELAY);
774
del_pending_request_by_type(entry, HIP_SERVICE_FULLRELAY);
821
HIP_DEBUG("The server has cancelled our registration " \
780
HIP_DEBUG("The server has cancelled our registration "
822
781
"to an unknown service.\n");
929
887
struct hip_pending_request *requests[request_count];
932
hip_get_pending_requests(entry, requests);
890
get_pending_requests(entry, requests);
934
892
/* If we have requested for a cancellation of a service
935
893
* we use lifetime of zero. Otherwise we must check
936
894
* that the requested lifetime falls between the offered
937
895
* lifetime boundaries. */
938
896
if (requests[0]->lifetime == 0) {
939
HIP_DEBUG("SERVICE CANCELATION \n");
897
HIP_DEBUG("SERVICE CANCELLATION \n");
940
898
valid_lifetime = 0;
942
900
valid_lifetime = MIN(requests[0]->lifetime,
1011
967
* message @c source_msg, takes action based on the contents of the REG_REQUEST
1012
968
* parameter and builds parameters in response to the HIP message @c target_msg.
1014
* First hip_has_duplicate_services() is called to check whether the
970
* First has_duplicate_services() is called to check whether the
1015
971
* parameter is malformed in a way that it has the same services listed more
1016
972
* than once. If the parameter proves to be malformed, the whole parameter is
1017
973
* omitted, none of the Reg Types in the REG_REQUEST are handled, and no
1019
975
* stress the server with malformed service requests. This is considered as a
1020
976
* protocol error and errno is set to EPROTO.
1022
* If the parameter passes the hip_has_duplicate_services() test, the parameter
978
* If the parameter passes the has_duplicate_services() test, the parameter
1023
979
* lifetime is investigated next. If it is zero i.e. the client is canceling a
1024
* service, hip_del_registration_server() is called. Otherwise the client is
1025
* registering to new services and hip_add_registration_server() is called.
980
* service, del_registration_server() is called. Otherwise the client is
981
* registering to new services and add_registration_server() is called.
1027
983
* Once the aforementioned functions return, a REG_RESPONSE and/or a required
1028
984
* number of REG_FAILED parameters are built to
1035
991
* @return -1 if the message @c source_msg did not contain a
1036
992
* REG_REQUEST parameter or the parameter had duplicate
1037
993
* services, zero otherwise.
1038
* @see hip_has_duplicate_services().
1039
* @see hip_add_registration_server().
1040
* @see hip_del_registration_server().
994
* @see has_duplicate_services().
995
* @see add_registration_server().
996
* @see del_registration_server().
1042
998
int hip_handle_param_reg_request(struct hip_hadb_state *entry,
1043
999
struct hip_common *source_msg,
1074
1030
reg_types = (const uint8_t *) hip_get_param_contents_direct(reg_request) +
1075
1031
sizeof(reg_request->lifetime);
1077
HIP_DEBUG("REG_REQUEST parameter found. Requested lifetime: 0x%x, " \
1033
HIP_DEBUG("REG_REQUEST parameter found. Requested lifetime: 0x%x, "
1078
1034
"number of service types requested: %d.\n",
1079
1035
reg_request->lifetime, type_count);
1081
1037
/* Check that the request has at most one value of each type. */
1082
if (hip_has_duplicate_services(reg_types, type_count)) {
1038
if (has_duplicate_services(reg_types, type_count)) {
1083
1039
/* We consider this as a protocol error, and do not build
1084
1040
* REG_FAILED parameters. The initiator may be rogue and
1085
1041
* trying to stress the server with malformed service
1088
1044
errno = EPROTO;
1089
HIP_ERROR("The REG_REQUEST parameter has duplicate services. " \
1045
HIP_ERROR("The REG_REQUEST parameter has duplicate services. "
1090
1046
"The whole parameter is omitted.\n");
1091
1047
/* As above. */
1095
1051
if (reg_request->lifetime == 0) {
1096
hip_del_registration_server(entry, reg_types, type_count,
1097
accepted_requests, &accepted_count,
1098
refused_requests, failure_types,
1052
del_registration_server(entry, reg_types, type_count,
1053
accepted_requests, &accepted_count,
1054
refused_requests, failure_types,
1101
hip_add_registration_server(entry, reg_request->lifetime, reg_types,
1102
type_count, accepted_requests,
1103
accepted_lifetimes, &accepted_count,
1104
refused_requests, failure_types,
1057
add_registration_server(entry, reg_request->lifetime, reg_types,
1058
type_count, accepted_requests,
1059
accepted_lifetimes, &accepted_count,
1060
refused_requests, failure_types,
1108
HIP_DEBUG("Number of accepted service requests: %d, number of refused " \
1064
HIP_DEBUG("Number of accepted service requests: %d, number of refused "
1109
1065
"service requests: %d.\n", accepted_count, refused_count);
1111
1067
/* The registration is now done. Next, we build the REG_RESPONSE and
1172
1128
* duplicate Reg Type one after the other.
1174
1130
* The parameter lifetime is investigated first. If it is zero i.e. the server
1175
* has canceled a service and hip_del_registration_client() is called. Otherwise
1131
* has canceled a service and del_registration_client() is called. Otherwise
1176
1132
* the server has granted us the services we requested and
1177
* hip_add_registration_client() is called.
1133
* add_registration_client() is called.
1179
1135
* @param entry a pointer to a host association which is registering.
1180
1136
* @param msg a pointer to HIP message from where to dig out the
1181
1137
* REG_RESPONSE parameter.
1182
1138
* @return -1 if the message @c msg did not contain a
1183
1139
* REG_RESPONSE parameter, zero otherwise.
1184
* @see hip_add_registration_client().
1185
* @see hip_del_registration_client().
1140
* @see add_registration_client().
1141
* @see del_registration_client().
1187
1143
int hip_handle_param_reg_response(struct hip_hadb_state *entry,
1188
1144
struct hip_common *msg)
1207
1163
sizeof(reg_response->lifetime);
1209
1165
if (reg_response->lifetime == 0) {
1210
hip_del_registration_client(entry, reg_types, type_count);
1166
del_registration_client(entry, reg_types, type_count);
1212
hip_add_registration_client(entry, reg_response->lifetime,
1213
reg_types, type_count);
1168
add_registration_client(entry, reg_response->lifetime,
1169
reg_types, type_count);
1245
1201
case HIP_REG_CANCEL_REQUIRED:
1246
1202
memcpy(type_string,
1247
"Cancellation of a previously granted service is " \
1249
sizeof("Cancellation of a previously granted service " \
1203
"Cancellation of a previously granted service is required.",
1204
sizeof("Cancellation of a previously granted service is required."));
1252
1206
case HIP_REG_TRANSIENT_CONDITIONS:
1253
1207
memcpy(type_string,
1254
"The server is currently unable to provide services " \
1208
"The server is currently unable to provide services "
1255
1209
"due to transient conditions.",
1256
sizeof("The server is currently unable to provide services " \
1210
sizeof("The server is currently unable to provide services "
1257
1211
"due to transient conditions."));
1301
1255
sizeof(reg_failed->failure_type);
1302
1256
reg_types = (const uint8_t *) hip_get_param_contents_direct(reg_failed) +
1303
1257
sizeof(reg_failed->failure_type);
1304
hip_get_registration_failure_string(reg_failed->failure_type,
1258
get_registration_failure_string(reg_failed->failure_type, reason);
1307
1260
for (; i < type_count; i++) {
1308
1261
switch (reg_types[i]) {
1309
1262
case HIP_SERVICE_RENDEZVOUS:
1311
HIP_DEBUG("The server has refused to grant us " \
1264
HIP_DEBUG("The server has refused to grant us "
1312
1265
"rendezvous service.\n%s\n", reason);
1313
1266
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_RVS);
1314
hip_del_pending_request_by_type(entry, HIP_SERVICE_RENDEZVOUS);
1267
del_pending_request_by_type(entry, HIP_SERVICE_RENDEZVOUS);
1315
1268
hip_hadb_set_peer_controls(entry, HIP_HA_CTRL_PEER_REFUSED_RVS);
1318
1271
case HIP_SERVICE_RELAY:
1320
HIP_DEBUG("The server has refused to grant us " \
1273
HIP_DEBUG("The server has refused to grant us "
1321
1274
"relay service.\n%s\n", reason);
1322
1275
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_RELAY);
1323
hip_del_pending_request_by_type(entry, HIP_SERVICE_RELAY);
1276
del_pending_request_by_type(entry, HIP_SERVICE_RELAY);
1324
1277
hip_hadb_set_peer_controls(entry, HIP_HA_CTRL_PEER_REFUSED_RELAY);
1327
1280
case HIP_SERVICE_FULLRELAY:
1329
HIP_DEBUG("The server has refused to grant us " \
1282
HIP_DEBUG("The server has refused to grant us "
1330
1283
"full relay service.\n%s\n", reason);
1331
1284
hip_hadb_cancel_local_controls(entry, HIP_HA_CTRL_LOCAL_REQ_FULLRELAY);
1332
hip_del_pending_request_by_type(entry, HIP_SERVICE_FULLRELAY);
1285
del_pending_request_by_type(entry, HIP_SERVICE_FULLRELAY);
1333
1286
hip_hadb_set_peer_controls(entry, HIP_HA_CTRL_PEER_REFUSED_FULLRELAY);
1337
HIP_DEBUG("The server has refused to grant us " \
1290
HIP_DEBUG("The server has refused to grant us "
1338
1291
"an unknown service (%u).\n%s\n",
1339
1292
reg_types[i], reason);
1340
hip_del_pending_request_by_type(entry, reg_types[i]);
1293
del_pending_request_by_type(entry, reg_types[i]);
1341
1294
hip_hadb_set_peer_controls(entry, HIP_HA_CTRL_PEER_REFUSED_UNSUP);
1424
1377
struct sockaddr_in sock_addr = { 0 };
1425
1378
struct in6_addr server_addr;
1426
1379
const hip_hit_t *dst_hit = NULL;
1427
struct hip_hadb_state *entry = NULL;
1380
struct hip_hadb_state *entry = NULL, *ha_opp = NULL;
1428
1381
struct in6_addr opp_hit = { { { 0 } } }, src_ip = { { { 0 } } };
1429
1382
struct in6_addr hit_local = { { { 0 } } };
1461
1414
if (dst_hit == NULL) {
1462
HIP_DEBUG("No HIT parameter found from the user " \
1415
HIP_DEBUG("No HIT parameter found from the user "
1463
1416
"message. Trying opportunistic mode \n");
1465
1418
} else if (dst_ip == NULL) {
1466
HIP_ERROR("No IPV6 parameter found from the user " \
1419
HIP_ERROR("No IPV6 parameter found from the user message.\n");
1470
1422
} else if (reg_req == NULL) {
1471
HIP_ERROR("No REG_REQUEST parameter found from the " \
1423
HIP_ERROR("No REG_REQUEST parameter found from the user message.\n");
1477
1428
if (!opp_mode) {
1478
1429
HIP_IFEL(hip_hadb_add_peer_info(dst_hit, dst_ip,
1480
-1, "Error on adding server " \
1431
-1, "Error on adding server "
1481
1432
"HIT to IP address mapping to the hadb.\n");
1483
1434
/* Fetch the hadb entry just created. */
1484
1435
entry = hip_hadb_try_to_find_by_peer_hit(dst_hit);
1486
1437
if (entry == NULL) {
1487
HIP_ERROR("Error on fetching server HIT to IP address " \
1438
HIP_ERROR("Error on fetching server HIT to IP address "
1488
1439
"mapping from the haDB.\n");
1509
1460
"Cannot find source address\n");
1462
/* @todo: Workaround for opp. registration when a mapping already
1463
* pre-exists. Similarly to the code in the end of this
1464
* function, this can be removed after bug id 592135 is
1466
#ifdef CONFIG_HIP_RVS
1467
ha_opp = hip_hadb_find_rvs_candidate_entry(&hit_local, dst_ip);
1468
#endif /* CONFIG_HIP_RVS */
1511
1470
HIP_IFEL(hip_hadb_add_peer_info_complete(&hit_local,
1593
/* Workaround for registration when a mapping already pre-exists
1594
* (inserted e.g. with "hipconf add map"). This can be removed
1595
* after bug id 592135 is resolved. */
1596
if (entry->state != HIP_STATE_NONE || HIP_STATE_UNASSOCIATED) {
1597
struct hip_common *msg2 = calloc(HIP_MAX_PACKET, 1);
1554
/** @todo Workaround for registration when a mapping already pre-exists
1555
* due to earlier registration. This and the code filling the
1556
* ha_opp can be removed after bug id 592135 is resolved. */
1557
if (!(entry->state == HIP_STATE_NONE || entry->state == HIP_STATE_UNASSOCIATED) || ha_opp) {
1558
struct hip_common *msg2 = calloc(HIP_MAX_PACKET, 1);
1559
hip_hit_t *peer_hit = ha_opp ? &ha_opp->hit_peer : &entry->hit_peer;
1598
1561
HIP_IFE(msg2 == 0, -1);
1599
1562
HIP_IFE(hip_build_user_hdr(msg2, HIP_MSG_RST, 0), -1);
1600
1563
HIP_IFE(hip_build_param_contents(msg2,
1603
1566
sizeof(hip_hit_t)),