chiark / gitweb /
comm,site: Make peer address configuration the responsibility of comm (udp)
[secnet.git] / site.c
diff --git a/site.c b/site.c
index 40819a4ab43a653d99a0df216e8d2f8faae5106a..88924009618bc6189c1c47458125cf057a9137a6 100644 (file)
--- a/site.c
+++ b/site.c
@@ -223,12 +223,10 @@ struct site {
     bool_t peer_mobile; /* Mobile client support */
     int32_t transport_peers_max;
     string_t tunname; /* localname<->remotename by default, used in logs */
-    string_t address; /* DNS name for bootstrapping, optional */
-    int remoteport; /* Port for bootstrapping, optional */
+    void *remote_addr_config; /* created and used by comm */
     struct netlink_if *netlink;
     struct comm_if **comms;
     int ncomms;
-    struct resolver_if *resolver;
     struct log_if *log;
     struct random_if *random;
     struct rsaprivkey_if *privkey;
@@ -793,28 +791,18 @@ static bool_t send_msg(struct site *st)
     }
 }
 
-static void site_resolve_callback(void *sst, struct in_addr *address)
+static void site_resolve_callback(void *sst, const struct comm_addr *address)
 {
     struct site *st=sst;
-    struct comm_addr ca_buf, *ca_use=0;
 
     if (st->state!=SITE_RESOLVE) {
        slog(st,LOG_UNEXPECTED,"site_resolve_callback called unexpectedly");
        return;
     }
-    if (address) {
-       struct sockaddr_in sin;
-       FILLZERO(sin);
-       sin.sin_family=AF_INET;
-       sin.sin_port=htons(st->remoteport);
-       sin.sin_addr=*address;
-       if (st->comms[0]->addr_construct(st->comms[0]->st, &ca_buf, &sin)) {
-           ca_use=&ca_buf;
-       }
-    } else {
-       slog(st,LOG_ERROR,"resolution of %s failed",st->address);
+    if (!address) {
+       slog(st,LOG_ERROR,"resolution of peer address failed");
     }
-    if (transport_compute_setupinit_peers(st,ca_use)) {
+    if (transport_compute_setupinit_peers(st,address)) {
        enter_new_state(st,SITE_SENTMSG1);
     } else {
        /* Can't figure out who to try to to talk to */
@@ -827,7 +815,7 @@ static bool_t initiate_key_setup(struct site *st, cstring_t reason)
 {
     if (st->state!=SITE_RUN) return False;
     slog(st,LOG_SETUP_INIT,"initiating key exchange (%s)",reason);
-    if (st->address) {
+    if (st->remote_addr_config) {
        slog(st,LOG_SETUP_INIT,"resolving peer address");
        return enter_state_resolve(st);
     } else if (transport_compute_setupinit_peers(st,0)) {
@@ -891,7 +879,7 @@ static void set_link_quality(struct site *st)
        quality=LINK_QUALITY_UP;
     else if (st->state==SITE_WAIT || st->state==SITE_STOP)
        quality=LINK_QUALITY_DOWN;
-    else if (st->address)
+    else if (st->remote_addr_config)
        quality=LINK_QUALITY_DOWN_CURRENT_ADDRESS;
     else if (transport_peers_valid(&st->peers))
        quality=LINK_QUALITY_DOWN_STALE_ADDRESS;
@@ -922,8 +910,8 @@ static bool_t enter_state_resolve(struct site *st)
     state_assert(st,st->state==SITE_RUN);
     slog(st,LOG_STATE,"entering state RESOLVE");
     st->state=SITE_RESOLVE;
-    st->resolver->request(st->resolver->st,st->address,
-                         site_resolve_callback,st);
+    st->comms[0]->peer_addr_request(st->comms[0]->st,st->remote_addr_config,
+                                   site_resolve_callback,st);
     return True;
 }
 
@@ -1352,15 +1340,12 @@ static list_t *site_apply(closure_t *self, struct cloc loc, dict_t *context,
        st->comms[i]=cl->interface;
     }
 
-    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);
 
+    st->remote_addr_config=st->comms[0]->peer_addr_config(
+       st->comms[0]->st,dict,loc,"site");
     st->privkey=find_cl_if(dict,"local-key",CL_RSAPRIVKEY,True,"site",loc);
-    st->address=dict_read_string(dict, "address", False, "site", loc);
-    if (st->address)
-       st->remoteport=dict_read_number(dict,"port",True,"site",loc,0);
-    else st->remoteport=0;
     st->pubkey=find_cl_if(dict,"key",CL_RSAPUBKEY,True,"site",loc);
 
     st->transform=