8 /*----- for all comms -----*/
10 struct comm_notify_entry {
13 LIST_ENTRY(comm_notify_entry) entry;
15 LIST_HEAD(comm_notify_list, comm_notify_entry) notify;
17 struct commcommon { /* must be first so that void* is comm_common* */
21 struct comm_notify_list notify;
22 struct buffer_if *rbuf;
25 void comm_request_notify(void *commst, void *nst, comm_notify_fn *fn);
26 void comm_release_notify(void *commst, void *nst, comm_notify_fn *fn);
28 bool_t comm_notify(struct comm_notify_list *notify, struct buffer_if *buf,
29 const struct comm_addr *ca);
30 /* Either: returns True, with message delivered and buffer freed.
31 * Or: False, if no-one wanted it - buffer still allocd'd.
32 * Ie, like comm_notify_fn. */
34 void comm_apply(struct commcommon *cc, void *st);
36 #define COMM_APPLY(st,cc,prefix,desc,loc) \
39 (cc)->cl.description=desc; \
40 (cc)->ops.sendmsg=prefix##sendmsg; \
41 (cc)->ops.addr_to_string=prefix##addr_to_string; \
43 /* void COMM_APPLY(SOMETHING *st, struct commcommon *FUNCTIONOF(st),
44 * prefix, "DESC", struct cloc loc);
45 * // Expects in scope: prefix##sendmsg, prefix##addr_to_string.
48 #define COMM_APPLY_STANDARD(st,cc,desc,args) \
49 item_t *item=list_elem(args,0); \
50 if (!item || item->type!=t_dict) { \
51 cfgfatal((cc)->loc,desc,"first argument must be a dictionary\n"); \
53 dict_t *d=item->data.dict; \
54 (cc)->rbuf=find_cl_if(d,"buffer",CL_BUFFER,True,desc,(cc)->loc)
55 /* void COMM_APPLY_STANDARD(SOMETHING *st, struct commcommon *cc,
56 * const char *desc, list_t *args);
58 * // item_t *item = <undefined>;
59 * // dict_t *dict = <construction dictionary argument>;
62 /*----- for udp-based comms -----*/
64 #define UDP_MAX_SOCKETS 3 /* 2 ought to do really */
66 #define MAX_AF MAX_RAW(AF_INET6,AF_INET)
71 bool_t experienced[/*0=recv,1=send*/2][MAX_AF+1][/*success?*/2];
76 struct udpsock socks[UDP_MAX_SOCKETS];
77 /* private for udp_socks_* */
78 struct udpcommon *uc; /* link to parent, for cfg, notify list, etc. */
79 struct poll_interest *interest;
91 bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us,
93 /* Caller should have filled in ->addr. Fills in us->fd,
94 ->experienced; updates ->addr. Logs any errors with lg_[v]perror. */
95 bool_t udp_import_socket(struct udpcommon *uc, struct udpsock *us,
96 int failmsgclass, int fd);
97 /* Like udp_make_socket, but caller provides fd. fd is not closed
100 void udp_destroy_socket(struct udpcommon *uc, struct udpsock *us);
101 /* Idempotent. No errors are possible. */
103 const char *af_name(int af);
104 void udp_sock_experienced(struct log_if *lg, struct udpcommon *uc,
105 struct udpsocks *socks, struct udpsock *us,
106 const union iaddr *dest, int af /* 0 means any */,
107 int r, int errnoval);
109 void udp_socks_register(struct udpcommon *uc, struct udpsocks *socks,
111 void udp_socks_deregister(struct udpcommon *uc, struct udpsocks *socks);
112 void udp_socks_childpersist(struct udpcommon *uc, struct udpsocks *socks);
114 #define UDP_APPLY_STANDARD(st,uc,desc) \
115 (uc)->use_proxy=False; \
116 (uc)->authbind=dict_read_string(d,"authbind",False,"udp",(uc)->cc.loc); \
117 (uc)->port=dict_read_number(d,"port",False,"udp",(uc)->cc.loc,0)
118 /* void UDP_APPLY_STANDARD(SOMETHING *st, struct udpcommon *uc,
120 * // Expects in scope: dict_t *d=...; as from COMM_APPLY_STANDARD
123 #endif /*COMM_COMMON_H*/