comm clientinfo: site: Pass comm-info to comm
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Apr 2017 12:11:43 +0000 (13:11 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 23 Apr 2017 16:14:43 +0000 (17:14 +0100)
Call each comm's clientinfo_fn on the comm-info dict, if any.
Pass the resulting struct clientinfo to sendmsg.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
README
site.c

diff --git a/README b/README
index 98ddec8..424f756 100644 (file)
--- a/README
+++ b/README
@@ -444,6 +444,9 @@ site: dict argument
     should be reflected in the local private interface MTU, ie the mtu
     parameter to netlink).  If this parameter is not set, or is set
     to 0, the default is to use the local private link mtu.
+  comm-info (dict): Information for the comm, used when this site
+    wants to transmit.  If the comm does not support this, it is
+    ignored.  (Currently nothing uses this.)
 
 Links involving mobile peers have some different tuning parameter
 default values, which are generally more aggressive about retrying key
diff --git a/site.c b/site.c
index 4ce4c24..dcac0ba 100644 (file)
--- a/site.c
+++ b/site.c
@@ -305,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;
@@ -1187,7 +1188,16 @@ static bool_t comm_addr_sendmsg(struct site *st,
                                const struct comm_addr *dest,
                                struct buffer_if *buf)
 {
-    return dest->comm->sendmsg(dest->comm->st, buf, dest, 0);
+    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)
@@ -2033,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; i<st->ncomms; 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);