X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=secnet.git;a=blobdiff_plain;f=comm-common.h;h=ebb71b83eaedeb61fe53efdf41bf1247f7b90940;hp=835d056b5d5117e8e0f99a6ee02c165bc06ee2dc;hb=55b79a8366a012388edabe7d2fad72a3a54ffe33;hpb=53f4e66603bcc2d21c70ad7a69db5fda6da5d645 diff --git a/comm-common.h b/comm-common.h index 835d056..ebb71b8 100644 --- a/comm-common.h +++ b/comm-common.h @@ -1,8 +1,27 @@ +/* + * This file is part of secnet. + * See README for full list of copyright holders. + * + * secnet is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version d of the License, or + * (at your option) any later version. + * + * secnet is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with secnet; if not, see + * https://www.gnu.org/licenses/gpl.html. + */ #ifndef COMM_COMMON_H #define COMM_COMMON_H #include "secnet.h" +#include "util.h" /*----- for all comms -----*/ @@ -21,6 +40,8 @@ struct commcommon { /* must be first so that void* is comm_common* */ struct buffer_if *rbuf; }; +struct comm_clientinfo *comm_clientinfo_ignore(void *state, dict_t*, + struct cloc cloc); void comm_request_notify(void *commst, void *nst, comm_notify_fn *fn); void comm_release_notify(void *commst, void *nst, comm_notify_fn *fn); @@ -33,9 +54,10 @@ bool_t comm_notify(struct comm_notify_list *notify, struct buffer_if *buf, void comm_apply(struct commcommon *cc, void *st); #define COMM_APPLY(st,cc,prefix,desc,loc) \ - (st)=safe_malloc(sizeof(*(st)), desc "_apply"); \ + NEW(st); \ (cc)->loc=loc; \ (cc)->cl.description=desc; \ + (cc)->ops.clientinfo=comm_clientinfo_ignore; \ (cc)->ops.sendmsg=prefix##sendmsg; \ (cc)->ops.addr_to_string=prefix##addr_to_string; \ comm_apply((cc),(st)) @@ -62,9 +84,12 @@ void comm_apply(struct commcommon *cc, void *st); #define UDP_MAX_SOCKETS 3 /* 2 ought to do really */ +#define MAX_AF MAX_RAW(AF_INET6,AF_INET) + struct udpsock { union iaddr addr; int fd; + bool_t experienced[/*0=recv,1=send*/2][MAX_AF+1][/*success?*/2]; }; struct udpsocks { @@ -72,6 +97,8 @@ struct udpsocks { struct udpsock socks[UDP_MAX_SOCKETS]; /* private for udp_socks_* */ struct udpcommon *uc; /* link to parent, for cfg, notify list, etc. */ + struct poll_interest *interest; + const char *desc; }; struct udpcommon { @@ -84,14 +111,31 @@ struct udpcommon { bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us, int failmsgclass); - /* Fills in us->fd. Logs any errors with lg_[v]perror. */ - -void udp_socks_register(struct udpcommon *uc, struct udpsocks *socks); + /* Caller should have filled in ->addr. Fills in us->fd, + ->experienced; updates ->addr. Logs any errors with lg_[v]perror. */ +bool_t udp_import_socket(struct udpcommon *uc, struct udpsock *us, + int failmsgclass, int fd); + /* Like udp_make_socket, but caller provides fd. fd is not closed + on error */ + +void udp_destroy_socket(struct udpcommon *uc, struct udpsock *us); + /* Idempotent. No errors are possible. */ + +const char *af_name(int af); +void udp_sock_experienced(struct log_if *lg, struct udpcommon *uc, + struct udpsocks *socks, struct udpsock *us, + const union iaddr *dest, int af /* 0 means any */, + int r, int errnoval); + +void udp_socks_register(struct udpcommon *uc, struct udpsocks *socks, + const char *desc); +void udp_socks_deregister(struct udpcommon *uc, struct udpsocks *socks); +void udp_socks_childpersist(struct udpcommon *uc, struct udpsocks *socks); #define UDP_APPLY_STANDARD(st,uc,desc) \ (uc)->use_proxy=False; \ (uc)->authbind=dict_read_string(d,"authbind",False,"udp",(uc)->cc.loc); \ - (uc)->port=dict_read_number(d,"port",True,"udp",(uc)->cc.loc,0) + (uc)->port=dict_read_number(d,"port",False,"udp",(uc)->cc.loc,0) /* void UDP_APPLY_STANDARD(SOMETHING *st, struct udpcommon *uc, * const char *desc); * // Expects in scope: dict_t *d=...; as from COMM_APPLY_STANDARD