-/*
- send a packet to the given vpn ip.
-*/
-int send_packet(ip_t to, vpn_packet_t *packet)
-{
- conn_list_t *cl;
-cp
- if((cl = lookup_conn(to)) == NULL)
- {
- if(debug_lvl > 3)
- {
- syslog(LOG_NOTICE, _("Trying to look up " IP_ADDR_S " in connection list failed!"),
- IP_ADDR_V(to));
- }
-
- /* Is this really necessary? If we can't find "to", then neither should any uplink. (GS) */
-
- return -1;
-
- for(cl = conn_list; cl != NULL && !cl->status.outgoing; cl = cl->next);
- if(!cl)
- { /* No open outgoing connection has been found. */
- if(debug_lvl > 3)
- syslog(LOG_NOTICE, _("There is no remote host I can send this packet to!"));
- return -1;
- }
- }
-
- /* If we ourselves have indirectdata flag set, we should send only to our uplink! */
-
- if(myself->flags & EXPORTINDIRECTDATA)
- {
- for(cl = conn_list; cl != NULL && !cl->status.outgoing; cl = cl->next);
- if(!cl)
- { /* No open outgoing connection has been found. */
- if(debug_lvl > 3)
- syslog(LOG_NOTICE, _("There is no remote host I can send this packet to!"));
- return -1;
- }
- }
- else
-
- /* If indirectdata flag is set for the destination we just looked up,
- * then real_ip is actually the vpn_ip of the gateway tincd
- * it is behind.
- */
-
- if(cl->flags & INDIRECTDATA)
- {
- if(debug_lvl > 3)
- syslog(LOG_NOTICE, _("Indirect packet to " IP_ADDR_S " via " IP_ADDR_S),
- IP_ADDR_V(cl->vpn_ip), IP_ADDR_V(cl->real_ip));
- if((cl = lookup_conn(cl->real_ip)) == NULL)
- {
- if(debug_lvl > 3)
- syslog(LOG_NOTICE, _("Indirect look up " IP_ADDR_S " in connection list failed!"),
- IP_ADDR_V(to));
-
- /* Gateway tincd dead? Should we kill it? (GS) */
-
- return -1;
- }
- if(cl->flags & INDIRECTDATA) /* This should not happen */
- {
- if(debug_lvl > 3)
- syslog(LOG_NOTICE, _("Double indirection for " IP_ADDR_S),
- IP_ADDR_V(to));
- return -1;
- }
- }
-
- if(my_key_expiry <= time(NULL))
- regenerate_keys();
-
- if(!cl->status.dataopen)
- if(setup_vpn_connection(cl) < 0)
- {
- syslog(LOG_ERR, _("Could not open UDP connection to " IP_ADDR_S " (%s)"), IP_ADDR_V(cl->vpn_ip), cl->hostname);
- return -1;
- }
-
- if(!cl->status.validkey)
- {
- if(debug_lvl > 3)
- syslog(LOG_INFO, _(IP_ADDR_S " (%s) has no valid key, queueing packet"), IP_ADDR_V(cl->vpn_ip), cl->hostname);
- add_queue(&(cl->sq), packet, packet->len + 2);
- if(!cl->status.waitingforkey)
- send_key_request(cl->vpn_ip); /* Keys should be sent to the host running the tincd */
- return 0;
- }
-
- if(!cl->status.active)
- {
- if(debug_lvl > 3)
- syslog(LOG_INFO, _(IP_ADDR_S " (%s) is not ready, queueing packet"), IP_ADDR_V(cl->vpn_ip), cl->hostname);
- add_queue(&(cl->sq), packet, packet->len + 2);
- return 0; /* We don't want to mess up, do we? */
- }
-
- /* can we send it? can we? can we? huh? */
-cp
- return xsend(cl, packet);
-}