X-Git-Url: https://git.distorted.org.uk/~mdw/secnet/blobdiff_plain/92ae57c54d1d725a6ff4e4e37fc1e20774261058..86420bb75f19f628ffd2d8ff9964e59ed99e3187:/site.c diff --git a/site.c b/site.c index 70cc316..dcac0ba 100644 --- a/site.c +++ b/site.c @@ -296,6 +296,7 @@ struct site { /* configuration information */ string_t localname; string_t remotename; + bool_t keepalive; bool_t local_mobile, peer_mobile; /* Mobile client support */ int32_t transport_peers_max; string_t tunname; /* localname<->remotename by default, used in logs */ @@ -304,6 +305,7 @@ struct site { uint32_t mtu_target; struct netlink_if *netlink; struct comm_if **comms; + struct comm_clientinfo **commclientinfos; int ncomms; struct resolver_if *resolver; struct log_if *log; @@ -1146,6 +1148,10 @@ static bool_t process_msg0(struct site *st, struct buffer_if *msg0, case LABEL_MSG7: /* We must forget about the current session. */ delete_keys(st,"request from peer",LOG_SEC); + /* probably, the peer is shutting down, and this is going to fail, + * but we need to be trying to bring the link up again */ + if (st->keepalive) + initiate_key_setup(st,"peer requested key teardown",0); return True; case LABEL_MSG9: /* Deliver to netlink layer */ @@ -1178,6 +1184,22 @@ static void dump_packet(struct site *st, struct buffer_if *buf, ok?"":" - fail"); } +static bool_t comm_addr_sendmsg(struct site *st, + const struct comm_addr *dest, + struct buffer_if *buf) +{ + int i; + struct comm_clientinfo *commclientinfo = 0; + + for (i=0; i < st->ncomms; i++) { + if (st->comms[i] == dest->comm) { + commclientinfo = st->commclientinfos[i]; + break; + } + } + return dest->comm->sendmsg(dest->comm->st, buf, dest, commclientinfo); +} + static uint32_t site_status(void *st) { return 0; @@ -1429,6 +1451,9 @@ static void enter_state_run(struct site *st) memset(st->dhsecret,0,st->dh->len); memset(st->sharedsecret,0,st->sharedsecretlen); set_link_quality(st); + + if (st->keepalive && !current_valid(st)) + initiate_key_setup(st, "keepalive", 0); } static bool_t ensure_resolving(struct site *st) @@ -1602,7 +1627,7 @@ static void generate_send_prod(struct site *st, slog(st,LOG_SETUP_INIT,"prodding peer for key exchange"); st->allow_send_prod=0; generate_prod(st,&st->scratch); - bool_t ok = source->comm->sendmsg(source->comm->st, &st->scratch, source); + bool_t ok = comm_addr_sendmsg(st, source, &st->scratch); dump_packet(st,&st->scratch,source,False,ok); } @@ -1967,6 +1992,8 @@ static list_t *site_apply(closure_t *self, struct cloc loc, dict_t *context, st->localname=dict_read_string(dict, "local-name", True, "site", loc); st->remotename=dict_read_string(dict, "name", True, "site", loc); + st->keepalive=dict_read_bool(dict,"keepalive",False,"site",loc,False); + st->peer_mobile=dict_read_bool(dict,"mobile",False,"site",loc,False); st->local_mobile= dict_read_bool(dict,"local-mobile",False,"site",loc,False); @@ -2016,6 +2043,14 @@ static list_t *site_apply(closure_t *self, struct cloc loc, dict_t *context, GET_CLOSURE_LIST("comm",comms,ncomms,CL_COMM); + NEW_ARY(st->commclientinfos, st->ncomms); + dict_t *comminfo = dict_read_dict(dict,"comm-info",False,"site",loc); + for (i=0; incomms; i++) { + st->commclientinfos[i] = + !comminfo ? 0 : + st->comms[i]->clientinfo(st->comms[i],comminfo,loc); + } + st->resolver=find_cl_if(dict,"resolver",CL_RESOLVER,True,"site",loc); st->log=find_cl_if(dict,"log",CL_LOG,True,"site",loc); st->random=find_cl_if(dict,"random",CL_RANDOMSRC,True,"site",loc); @@ -2349,8 +2384,7 @@ void transport_xmit(struct site *st, transport_peers *peers, int nfailed=0; for (slot=0; slotnpeers; slot++) { transport_peer *peer=&peers->peers[slot]; - bool_t ok = - peer->addr.comm->sendmsg(peer->addr.comm->st, buf, &peer->addr); + bool_t ok = comm_addr_sendmsg(st, &peer->addr, buf); if (candebug) dump_packet(st, buf, &peer->addr, False, ok); if (!ok) {