本文整理汇总了C++中HIP_DEBUG函数的典型用法代码示例。如果您正苦于以下问题:C++ HIP_DEBUG函数的具体用法?C++ HIP_DEBUG怎么用?C++ HIP_DEBUG使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HIP_DEBUG函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: send_bex_store_update_to_hipd
/** sends a list of all available anchor elements in the BEX store
* to the hipd
*
* @param hcstore the BEX store
* @param use_hash_trees indicates whether hash chains or hash trees are stored
* @return 0 on success, -1 on error
*/
int send_bex_store_update_to_hipd(struct hchain_store *hcstore,
const int use_hash_trees)
{
struct hip_common *msg = NULL;
int err = 0;
HIP_ASSERT(hcstore != NULL);
HIP_DEBUG("sending bex-store update to hipd...\n");
HIP_IFEL(!(msg = create_bex_store_update_msg(hcstore, use_hash_trees)),
-1, "failed to create bex store anchors update message\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;
}
示例2: hip_setup_hit_sp_pair
int hip_setup_hit_sp_pair(hip_hit_t *src_hit, hip_hit_t *dst_hit,
struct in6_addr *src_addr,
struct in6_addr *dst_addr, u8 proto,
int use_full_prefix, int update)
{
int so, len, err = 0;
u_int prefs, prefd;
u8 prefix = (use_full_prefix) ? 128 : HIP_HIT_PREFIX_LEN;
int cmd = update ? SADB_X_SPDUPDATE : SADB_X_SPDADD;
HIP_DEBUG("\n");
HIP_IFEL(((so = pfkey_open()) < 0), -1, "ERROR in opening pfkey socket: %s\n", ipsec_strerror());
HIP_DEBUG("Adding a pair of SP\n");
HIP_IFEBL((hip_pfkey_policy_modify(so, dst_hit, prefix, src_hit,
prefix, src_addr, dst_addr,
proto, cmd, IPSEC_DIR_INBOUND)<0),
-1, pfkey_close(so), "ERROR in %s the inbound policy\n", update ? "updating" : "adding");
HIP_IFEL(((so = pfkey_open()) < 0), -1, "ERROR in opening pfkey socket: %s\n", ipsec_strerror());
HIP_IFEBL((hip_pfkey_policy_modify(so, src_hit, prefix, dst_hit,
prefix, dst_addr, src_addr,
proto, cmd, IPSEC_DIR_OUTBOUND)<0),
-1, pfkey_close(so), "ERROR in %s the outbound policy\n", update ? "updating" : "adding");
return 0;
out_err:
return err;
}
示例3: hip_handle_echo_request_param
/**
* Handle ECHO_REQUEST_UNSIGNED parameter.
*
* @param packet_type The packet type of the control message (RFC 5201, 5.3.)
* @param ha_state The host association state (RFC 5201, 4.4.1.)
* @param ctx Pointer to the packet context, containing all information for
* the packet handling (received message, source and destination
* address, the ports and the corresponding entry from the host
* association database).
*
* @return zero on success, or negative error value on error.
*/
int hip_handle_echo_request_param(UNUSED const uint8_t packet_type,
UNUSED const uint32_t ha_state,
struct hip_packet_context *ctx)
{
const struct hip_echo_request *echo_request = NULL;
int err = 0;
if (!(echo_request = hip_get_param(ctx->input_msg,
HIP_PARAM_ECHO_REQUEST))) {
HIP_DEBUG("no ECHO_REQUEST parameter in UPDATE packet, skipping\n");
/* This condition is no error! There simply was no request by the peer
* to add a ECHO_RESPONSE parameter to the outbound message. */
return 0;
}
HIP_DEBUG("echo opaque data len=%d\n",
hip_get_param_contents_len(echo_request));
HIP_HEXDUMP("ECHO_REQUEST ",
(const uint8_t *) echo_request + sizeof(struct hip_tlv_common),
hip_get_param_contents_len(echo_request));
HIP_IFEL(hip_build_param_echo(ctx->output_msg,
(const uint8_t *) echo_request + sizeof(struct hip_tlv_common),
hip_get_param_contents_len(echo_request), 0, 0),
-1, "Building of ECHO_RESPONSE failed\n");
out_err:
return err;
}
示例4: opendht_rm
/**
* opendht_rm - Builds XML RPC packet and sends it through given socket and reads the response
* @param sockfd Socket to be used with the send
* @param key Key for the openDHT
* @param value Value to be removed to the openDHT
* @param secret Value to be used as a secret in remove
* @param host Host address
* @param response Buffer where the possible error message is saved
*
* @return Returns integer -1 on error, on success 0
*/
int opendht_rm(int sockfd,
unsigned char * key,
unsigned char * value,
unsigned char * secret,
unsigned char * host,
int opendht_port,
int opendht_ttl)
{
int key_len = 0;
char put_packet[HIP_MAX_PACKET];
char tmp_key[21];
key_len = opendht_handle_key(key, tmp_key);
/* Rm operation */
memset(put_packet, '\0', sizeof(put_packet));
if (build_packet_rm((unsigned char *)tmp_key,
key_len,
(unsigned char *)value,
strlen((char *)value),
(unsigned char *)secret,
strlen((char *)secret),
opendht_port,
(unsigned char *)host,
put_packet, opendht_ttl) != 0)
{
HIP_DEBUG("Rm packet creation failed.\n");
return(-1);
}
_HIP_DEBUG("Host address in OpenDHT rm : %s\n", host);
HIP_DEBUG("Actual OpenDHT send starts here\n");
send(sockfd, put_packet, strlen(put_packet), 0);
return(0);
}
示例5: hip_regen_dh_keys
/**
* hip_regen_dh_keys - Regenerate Diffie-Hellman keys for HIP
* @param bitmask Mask of groups to generate.
*
* Use only this function to generate DH keys.
*/
void hip_regen_dh_keys(u32 bitmask)
{
DH *tmp,*okey;
int maxmask,i;
int cnt = 0;
/* if MAX_DH_GROUP_ID = 4 --> maxmask = 0...01111 */
maxmask = (1 << (HIP_MAX_DH_GROUP_ID+1)) - 1;
bitmask &= maxmask;
for(i=1; i<=HIP_MAX_DH_GROUP_ID; i++) {
if (bitmask & (1 << i)) {
tmp = hip_generate_dh_key(i);
if (!tmp) {
HIP_INFO("Error while generating group: %d\n",i);
continue;
}
okey = dh_table[i];
dh_table[i] = tmp;
hip_free_dh(okey);
cnt++;
HIP_DEBUG("DH key for group %d generated\n",i);
}
}
HIP_DEBUG("%d keys generated\n",cnt);
}
示例6: hip_daemon_bind_socket
int hip_daemon_bind_socket(int socket, struct sockaddr *sa) {
int err = 0, port = 0, on = 1;
struct sockaddr_in6 *addr = (struct sockaddr_in6 *) sa;
HIP_ASSERT(addr->sin6_family == AF_INET6);
errno = 0;
if (setsockopt(socket, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
HIP_DEBUG ("Failed to set socket option SO_REUSEADDR %s \n", strerror(errno));
}
if (addr->sin6_port) {
HIP_DEBUG("Bind to fixed port %d\n", addr->sin6_port);
err = bind(socket,(struct sockaddr *)addr,
sizeof(struct sockaddr_in6));
err = -errno;
goto out_err;
}
/* try to bind first to a priviledged port and then to ephemeral */
port = 1000;
while (port++ < 61000) {
_HIP_DEBUG("trying bind() to port %d\n", port);
addr->sin6_port = htons(port);
err = bind(socket,(struct sockaddr *)addr,
hip_sockaddr_len(addr));
if (err == -1) {
if (errno == EACCES) {
/* Ephemeral ports:
/proc/sys/net/ipv4/ip_local_port_range */
_HIP_DEBUG("Skipping to ephemeral range\n");
port = 32768;
errno = 0;
err = 0;
} else if (errno == EADDRINUSE) {
_HIP_DEBUG("Port %d in use, skip\n", port);
errno = 0;
err = 0;
} else {
HIP_ERROR("Error %d bind() wasn't succesful\n",
errno);
err = -1;
goto out_err;
}
}
else {
_HIP_DEBUG("Bind() to port %d successful\n", port);
goto out_err;
}
}
if (port == 61000) {
HIP_ERROR("All privileged ports were occupied\n");
err = -1;
}
out_err:
return err;
}
示例7: hip_firewall_set_esp_relay
/**
* tell firewall to turn on or off the ESP relay mode
*
* @param action HIP_MSG_OFFER_FULLRELAY or HIP_MSG_CANCEL_FULLRELAY
*
* @return zero on success or negative on failure
*/
int hip_firewall_set_esp_relay(int action)
{
struct hip_common *msg = NULL;
int err = 0;
int sent;
HIP_DEBUG("Setting ESP relay to %d\n", action);
if (!(msg = hip_msg_alloc())) {
return -ENOMEM;
}
HIP_IFEL(hip_build_user_hdr(msg,
action ? HIP_MSG_OFFER_FULLRELAY : HIP_MSG_CANCEL_FULLRELAY, 0),
-1, "Build header failed\n");
sent = hip_sendto_firewall(msg);
if (sent < 0) {
HIP_PERROR("Send to firewall failed: ");
err = -1;
goto out_err;
}
HIP_DEBUG("Sent %d bytes to firewall.\n", sent);
out_err:
free(msg);
return err;
}
示例8: run_nsupdate
/*
* Execute nsupdate.pl with IP and HIT given as environment variables
*/
int run_nsupdate(char *ips, char *hit, int start)
{
struct sigaction act;
pid_t child_pid;
HIP_DEBUG("Updating dns records...\n");
act.sa_handler = sig_chld;
/* We don't want to block any other signals */
sigemptyset(&act.sa_mask);
/*
* We're only interested in children that have terminated, not ones
* which have been stopped (eg user pressing control-Z at terminal)
*/
act.sa_flags = SA_NOCLDSTOP | SA_RESTART;
/* Make the handler effective */
if (sigaction(SIGCHLD, &act, NULL) < 0) {
HIP_PERROR("sigaction");
return ERR;
}
/* Let us fork to execute nsupdate as a separate process */
child_pid=fork();
if (child_pid<0) {
HIP_PERROR("fork");
return ERR;
}
else if (child_pid == 0) {// CHILD
char start_str[2];
#if 0
/* Close open sockets since FD_CLOEXEC was not used */
close_all_fds_except_stdout_and_stderr();
#endif
snprintf(start_str, sizeof(start_str), "%i", start);
char *env_ips = make_env(VAR_IPS, ips);
char *env_hit = make_env(VAR_HIT, hit);
char *env_start = make_env(VAR_START, start_str);
char *cmd[] = { NSUPDATE_ARG0, NULL };
char *env[] = { env_ips, env_hit, env_start, NULL };
HIP_DEBUG("Executing %s with %s; %s; %s\n", NSUPDATE_PL, env_hit, env_ips, env_start);
execve (NSUPDATE_PL, cmd, env);
/* Executed only if error */
HIP_PERROR("execve");
exit(1); // just in case
}
else {// PARENT
/* We execute waitpid in SIGCHLD handler */
return OK;
}
}
示例9: hip_handle_locator_parameter
/**
* Handle LOCATOR parameter in first update packet.
*
* @param packet_type The packet type of the control message (RFC 5201, 5.3.)
* @param ha_state The host association state (RFC 5201, 4.4.1.)
* @param ctx Pointer to the packet context, containing all information for
* the packet handling (received message, source and destination
* address, the ports and the corresponding entry from the host
* association database).
*
* @return zero on success, or negative error value on error.
*/
int hip_handle_locator_parameter(UNUSED const uint8_t packet_type,
UNUSED const uint32_t ha_state,
struct hip_packet_context *ctx)
{
int locator_addr_count = 0;
union hip_locator_info_addr *locator_info_addr = NULL;
struct hip_locator_info_addr_item *locator_address_item = NULL;
struct update_state *localstate = NULL;
struct hip_locator *locator = NULL;
if (hip_classify_update_type(ctx->input_msg) == FIRST_UPDATE_PACKET) {
if (!(locator = hip_get_param_readwrite(ctx->input_msg,
HIP_PARAM_LOCATOR))) {
HIP_ERROR("no LOCATOR parameter found\n");
return -1;
}
locator_addr_count = hip_get_locator_addr_item_count(locator);
HIP_DEBUG("LOCATOR has %d address(es), loc param len=%d\n",
locator_addr_count, hip_get_param_total_len(locator));
// Empty the addresses_to_send_echo_request list before adding the
// new addresses
localstate = lmod_get_state_item(ctx->hadb_entry->hip_modular_state,
"update");
HIP_DEBUG("hip_get_state_item returned localstate: %p\n", localstate);
hip_remove_addresses_to_send_echo_request(localstate);
locator_address_item = (struct hip_locator_info_addr_item *) (locator + 1);
HIP_DEBUG_IN6ADDR("Adding IP source address to locator set",
&ctx->src_addr);
if (!hip_add_address_to_send_echo_request(localstate, ctx->src_addr)) {
HIP_ERROR("Adding source address to the container for update locators failed!\n");
return -1;
}
for (int i = 0; i < locator_addr_count; i++) {
locator_info_addr = hip_get_locator_item(locator_address_item, i);
const struct in6_addr *const peer_addr = hip_get_locator_item_address(locator_info_addr);
if (ipv6_addr_cmp(&ctx->src_addr, peer_addr) != 0) {
HIP_DEBUG_IN6ADDR("adding locator", peer_addr);
if (!hip_add_address_to_send_echo_request(localstate, *peer_addr)) {
HIP_ERROR("Adding an address to the container for update locators failed!\n");
return -1;
}
}
}
hip_print_addresses_to_send_update_request(ctx->hadb_entry);
}
return 0;
}
示例10: hip_handle_retransmission
/**
* an iterator to handle packet retransmission for a given host association
*
* @param entry the host association which to handle
* @param current_time current time
* @return zero on success or negative on failure
*/
static int hip_handle_retransmission(struct hip_hadb_state *entry,
void *current_time)
{
int err = 0;
time_t *now = (time_t *) current_time;
if (entry->hip_msg_retrans.buf == NULL ||
entry->hip_msg_retrans.count == 0) {
goto out_err;
}
/* check if the last transmision was at least RETRANSMIT_WAIT seconds ago */
if (*now - HIP_RETRANSMIT_WAIT > entry->hip_msg_retrans.last_transmit) {
if ((entry->hip_msg_retrans.count > 0) && entry->hip_msg_retrans.buf &&
((entry->state != HIP_STATE_ESTABLISHED && entry->retrans_state != entry->state) ||
(entry->update_state != 0 && entry->retrans_state != entry->update_state) ||
entry->light_update_retrans == 1)) {
HIP_DEBUG("state=%d, retrans_state=%d, update_state=%d\n",
entry->state, entry->retrans_state, entry->update_state, entry->retrans_state);
/* @todo: verify that this works over slow ADSL line */
err = hip_send_pkt(&entry->hip_msg_retrans.saddr,
&entry->hip_msg_retrans.daddr,
(entry->nat_mode ? hip_get_local_nat_udp_port() : 0),
entry->peer_udp_port,
entry->hip_msg_retrans.buf,
entry, 0);
/* Set entry state, if previous state was unassosiated
* and type is I1. */
if (!err && hip_get_msg_type(entry->hip_msg_retrans.buf)
== HIP_I1 && entry->state == HIP_STATE_UNASSOCIATED) {
HIP_DEBUG("Resent I1 succcesfully\n");
entry->state = HIP_STATE_I1_SENT;
}
entry->hip_msg_retrans.count--;
/* set the last transmission time to the current time value */
time(&entry->hip_msg_retrans.last_transmit);
} else {
if (entry->hip_msg_retrans.buf) {
entry->hip_msg_retrans.count = 0;
memset(entry->hip_msg_retrans.buf, 0, HIP_MAX_NETWORK_PACKET);
}
if (entry->state == HIP_STATE_ESTABLISHED) {
entry->retrans_state = entry->update_state;
} else {
entry->retrans_state = entry->state;
}
}
}
out_err:
return err;
}
示例11: hip_hit_to_ip
/*
* checks for ip address for hit
*/
int hip_hit_to_ip(hip_hit_t *hit, struct in6_addr *retval) {
struct addrinfo *rp = NULL; // no C99 :(
char hit_to_ip_hostname[64+HIT_TO_IP_ZONE_MAX_LEN+1];
int found_addr = 0;
struct addrinfo hints;
struct addrinfo *result = NULL;
int res;
if ((hit == NULL)||(retval == NULL))
return ERR;
if (hip_get_hit_to_ip_hostname(hit, hit_to_ip_hostname, sizeof(hit_to_ip_hostname))!=OK)
return ERR;
memset(&hints, 0, sizeof(hints));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_DGRAM; /* Datagram socket. Right? */
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
hints.ai_protocol = 0; /* Any protocol */
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
/* getaddrinfo is too complex for DNS lookup, but let us use it now */
res = getaddrinfo( hit_to_ip_hostname, NULL, &hints, &result );
HIP_DEBUG("getaddrinfo(%s) returned %d\n", hit_to_ip_hostname, res);
if (res!=0) {
HIP_DEBUG("getaddrinfo error %s\n", gai_strerror(res));
return ERR;
}
/* Look at the list and return only one address, let us prefer AF_INET */
for (rp = result; rp != NULL; rp = rp->ai_next) {
HIP_DEBUG_SOCKADDR("getaddrinfo result", rp->ai_addr);
if (rp->ai_family == AF_INET) {
struct sockaddr_in *tmp_sockaddr_in_ptr = (struct sockaddr_in *) (rp->ai_addr);
IPV4_TO_IPV6_MAP(&(tmp_sockaddr_in_ptr->sin_addr), retval)
found_addr = 1;
break;
} else if (rp->ai_family == AF_INET6) {
struct sockaddr_in6 *tmp_sockaddr_in6_ptr = (struct sockaddr_in6 *) (rp->ai_addr);
ipv6_addr_copy(retval, &(tmp_sockaddr_in6_ptr->sin6_addr));
found_addr = 1;
}
}
if (result)
freeaddrinfo(result);
if (found_addr)
return OK;
else
return ERR;
}
示例12: hip_delete_sa
void hip_delete_sa(u32 spi, struct in6_addr *peer_addr, struct in6_addr *dst_addr,
int direction, hip_ha_t *entry)
{
int so, len, err = 0;
struct sockaddr_storage ss_addr, dd_addr;
struct sockaddr *saddr;
struct sockaddr *daddr;
in_port_t sport, dport;
/* @todo: sport and dport should be used! */
if (direction == HIP_SPI_DIRECTION_OUT)
{
sport = entry->local_udp_port;
dport = entry->peer_udp_port;
entry->outbound_sa_count--;
if (entry->outbound_sa_count < 0) {
HIP_ERROR("Warning: out sa count negative\n");
entry->outbound_sa_count = 0;
}
}
else
{
sport = entry->peer_udp_port;
dport = entry->local_udp_port;
entry->inbound_sa_count--;
if (entry->inbound_sa_count < 0) {
HIP_ERROR("Warning: in sa count negative\n");
entry->inbound_sa_count = 0;
}
}
saddr = (struct sockaddr*) &ss_addr;
daddr = (struct sockaddr*) &dd_addr;
HIP_DEBUG("\n");
HIP_DEBUG("spi=0x%x\n", spi);
HIP_DEBUG_IN6ADDR("peer_addr", peer_addr);
HIP_DEBUG_IN6ADDR("dst_addr", dst_addr);
// Sanity check
HIP_IFEL((!peer_addr || !dst_addr), -1, "Addresses not valid when deleting SA's\n");
HIP_IFEL(((so = pfkey_open()) < 0), -1, "ERROR in opening pfkey socket: %s\n", ipsec_strerror());
get_sock_addr_from_in6(saddr, peer_addr);
get_sock_addr_from_in6(daddr, dst_addr);
HIP_IFEBL(((len = pfkey_send_delete(so, SADB_SATYPE_ESP, HIP_IPSEC_DEFAULT_MODE, saddr, daddr, spi))<0), -1,
pfkey_close(so), "ERROR in deleting sa %s", ipsec_strerror());
out_err:
return;
}
示例13: hip_flush_all_sa
int hip_flush_all_sa()
{
int so, len, err = 0;
HIP_DEBUG("\n");
HIP_IFEL(((so = pfkey_open()) < 0), -1, "ERROR in opening pfkey socket: %s\n", ipsec_strerror());
HIP_DEBUG("Flushing all SA's\n");
HIP_IFEBL(((len = pfkey_send_flush(so, SADB_SATYPE_ESP))<0), -1,
pfkey_close(so), "ERROR in flushing policies %s\n", ipsec_strerror());
return len;
out_err:
return err;
}
示例14: hip_firewall_is_alive
/**
*
* get the current running status of firewall
*
* @return one if firewall is running or zero otherwise
*/
int hip_firewall_is_alive(void)
{
#ifdef CONFIG_HIP_FIREWALL
if (hip_firewall_status) {
HIP_DEBUG("Firewall is alive.\n");
} else {
HIP_DEBUG("Firewall is not alive.\n");
}
return hip_firewall_status;
#else
HIP_DEBUG("Firewall is disabled.\n");
return 0;
#endif // CONFIG_HIP_FIREWALL
}
示例15: hip_flush_all_policy
int hip_flush_all_policy()
{
int so, len, err = 0;
HIP_DEBUG("\n");
HIP_IFEL(((so = pfkey_open()) < 0), -1, "ERROR in opening pfkey socket: %s\n", ipsec_strerror());
HIP_DEBUG("FLushing all SP's\n");
HIP_IFEBL(((len = pfkey_send_spdflush(so))<0), -1,
pfkey_close(so), "ERROR in flushing policies %s\n", ipsec_strerror());
HIP_DEBUG("FLushing all SP's was successful\n");
return len;
out_err:
HIP_ERROR("FLushing all SP's\n");
return err;
}