Commit | Line | Data |
---|---|---|
2fe58dfd SE |
1 | /* UDP send/receive module for secnet */ |
2 | ||
3 | /* This module enables sites to communicate by sending UDP | |
4 | * packets. When an instance of the module is created we can | |
5 | * optionally bind to a particular local IP address (not implemented | |
6 | * yet). | |
7 | * | |
2fe58dfd SE |
8 | * Packets are offered to registered receivers in turn. Once one |
9 | * accepts it, it isn't offered to any more. */ | |
10 | ||
8689b3a9 | 11 | #include "secnet.h" |
2fe58dfd SE |
12 | #include <stdio.h> |
13 | #include <unistd.h> | |
14 | #include <fcntl.h> | |
15 | #include <string.h> | |
16 | #include <errno.h> | |
2fe58dfd | 17 | #include <sys/socket.h> |
b2a56f7c | 18 | #include <sys/wait.h> |
5edf478f IJ |
19 | #include <netinet/in.h> |
20 | #include <arpa/inet.h> | |
2fe58dfd | 21 | #include "util.h" |
dd9209d1 | 22 | #include "magic.h" |
794f2398 | 23 | #include "unaligned.h" |
ff05a229 | 24 | #include "ipaddr.h" |
136740e6 | 25 | #include "magic.h" |
54d5ef00 | 26 | #include "comm-common.h" |
2fe58dfd | 27 | |
2fe58dfd SE |
28 | static comm_sendmsg_fn udp_sendmsg; |
29 | ||
2fe58dfd | 30 | struct udp { |
763e458f IJ |
31 | struct udpcommon uc; |
32 | struct udpsocks socks; | |
93910f6a | 33 | bool_t addr_configured; |
2fe58dfd SE |
34 | }; |
35 | ||
08b62a6c IJ |
36 | /* |
37 | * Re comm_addr.ix: This field allows us to note in the comm_addr | |
38 | * which socket an incoming packet was received on. This is required | |
39 | * for conveniently logging the actual source of a packet. But the ix | |
40 | * does not formally form part of the address: it is not used when | |
41 | * sending, nor when comparing two comm_addrs. | |
42 | * | |
43 | * The special value -1 means that the comm_addr was constructed by | |
44 | * another module in secnet (eg the resolver), rather than being a | |
45 | * description of the source of an incoming packet. | |
46 | */ | |
47 | ||
54d5ef00 IJ |
48 | static const char *udp_addr_to_string(void *commst, const struct comm_addr *ca) |
49 | { | |
5edf478f | 50 | struct udp *st=commst; |
763e458f | 51 | struct udpsocks *socks=&st->socks; |
5edf478f | 52 | static char sbuf[100]; |
08b62a6c | 53 | int ix=ca->ix>=0 ? ca->ix : 0; |
5edf478f | 54 | |
7d31df0e | 55 | assert(ix>=0 && ix<socks->n_socks); |
08b62a6c | 56 | snprintf(sbuf, sizeof(sbuf), "udp:%s%s-%s", |
7d31df0e | 57 | iaddr_to_string(&socks->socks[ix].addr), |
bfc34aff | 58 | ca->ix<0 && socks->n_socks>1 ? "&" : "", |
08b62a6c | 59 | iaddr_to_string(&ca->ia)); |
5edf478f IJ |
60 | return sbuf; |
61 | } | |
62 | ||
f7af3192 IJ |
63 | static int udp_socks_beforepoll(void *state, struct pollfd *fds, int *nfds_io, |
64 | int *timeout_io) | |
2fe58dfd | 65 | { |
f7af3192 | 66 | struct udpsocks *socks=state; |
08b62a6c | 67 | int i; |
7d31df0e IJ |
68 | BEFOREPOLL_WANT_FDS(socks->n_socks); |
69 | for (i=0; i<socks->n_socks; i++) { | |
70 | fds[i].fd=socks->socks[i].fd; | |
08b62a6c IJ |
71 | fds[i].events=POLLIN; |
72 | } | |
2fe58dfd SE |
73 | return 0; |
74 | } | |
75 | ||
2d7478f7 IJ |
76 | const char *af_name(int af) |
77 | { | |
78 | switch (af) { | |
79 | case AF_INET6: return "IPv6"; | |
80 | case AF_INET: return "IPv4"; | |
81 | case 0: return "(any)"; | |
82 | default: abort(); | |
83 | } | |
84 | } | |
85 | ||
86 | void udp_sock_experienced(struct log_if *lg, struct udpcommon *uc, | |
c72d679d | 87 | struct udpsocks *socks, struct udpsock *us, |
6c5889e6 | 88 | const union iaddr *dest, int af, |
2d7478f7 IJ |
89 | int r, int errnoval) |
90 | { | |
91 | bool_t success=r>=0; | |
6c5889e6 | 92 | if (us->experienced[!!dest][af][success]++) |
2d7478f7 IJ |
93 | return; |
94 | lg_perror(lg, uc->cc.cl.description, &uc->cc.loc, | |
95 | success ? M_INFO : M_WARNING, | |
96 | success ? 0 : errnoval, | |
6c5889e6 | 97 | "%s %s experiencing some %s %s%s%s%s%s%s", |
c72d679d | 98 | socks->desc,iaddr_to_string(&us->addr), |
2d7478f7 | 99 | success?"success":"trouble", |
6c5889e6 IJ |
100 | dest?"transmitting":"receiving", |
101 | af?" ":"", af?af_name(af):"", | |
102 | dest?" (to ":"", | |
103 | dest?iaddr_to_string(dest):"", | |
104 | dest?")":""); | |
2d7478f7 IJ |
105 | } |
106 | ||
f7af3192 | 107 | static void udp_socks_afterpoll(void *state, struct pollfd *fds, int nfds) |
763e458f | 108 | { |
f7af3192 IJ |
109 | struct udpsocks *socks=state; |
110 | struct udpcommon *uc=socks->uc; | |
a32d56fb | 111 | union iaddr from; |
b1a0f651 | 112 | socklen_t fromlen; |
2fe58dfd SE |
113 | bool_t done; |
114 | int rv; | |
08b62a6c | 115 | int i; |
2fe58dfd | 116 | |
763e458f IJ |
117 | struct commcommon *cc=&uc->cc; |
118 | ||
119 | for (i=0; i<socks->n_socks; i++) { | |
56c8ed69 | 120 | struct udpsock *us=&socks->socks[i]; |
08b62a6c IJ |
121 | if (i>=nfds) continue; |
122 | if (!(fds[i].revents & POLLIN)) continue; | |
56c8ed69 IJ |
123 | assert(fds[i].fd == us->fd); |
124 | int fd=us->fd; | |
2fe58dfd SE |
125 | do { |
126 | fromlen=sizeof(from); | |
7d31df0e IJ |
127 | BUF_ASSERT_FREE(cc->rbuf); |
128 | BUF_ALLOC(cc->rbuf,"udp_afterpoll"); | |
129 | buffer_init(cc->rbuf,calculate_max_start_pad()); | |
130 | rv=recvfrom(fd, cc->rbuf->start, | |
131 | buf_remaining_space(cc->rbuf), | |
a32d56fb | 132 | 0, &from.sa, &fromlen); |
2fe58dfd | 133 | if (rv>0) { |
7d31df0e IJ |
134 | cc->rbuf->size=rv; |
135 | if (uc->use_proxy) { | |
ff05a229 SE |
136 | /* Check that the packet came from our poxy server; |
137 | we shouldn't be contacted directly by anybody else | |
138 | (since they can trivially forge source addresses) */ | |
9c44ef13 | 139 | if (!iaddr_equal(&from,&uc->proxy,False)) { |
ff05a229 SE |
140 | Message(M_INFO,"udp: received packet that's not " |
141 | "from the proxy\n"); | |
7d31df0e | 142 | BUF_FREE(cc->rbuf); |
ff05a229 SE |
143 | continue; |
144 | } | |
a32d56fb IJ |
145 | /* proxy protocol supports ipv4 transport only */ |
146 | from.sa.sa_family=AF_INET; | |
c1ddd026 | 147 | BUF_GET_BYTES(unprepend,cc->rbuf,&from.sin.sin_addr,4); |
7d31df0e | 148 | buf_unprepend(cc->rbuf,2); |
c1ddd026 | 149 | BUF_GET_BYTES(unprepend,cc->rbuf,&from.sin.sin_port,2); |
ff05a229 | 150 | } |
8534d602 | 151 | struct comm_addr ca; |
7d31df0e | 152 | ca.comm=&cc->ops; |
a32d56fb | 153 | ca.ia=from; |
08b62a6c | 154 | ca.ix=i; |
54d5ef00 | 155 | done=comm_notify(&cc->notify, cc->rbuf, &ca); |
c72d679d IJ |
156 | if (done) { |
157 | udp_sock_experienced(0,uc,socks,us,0, | |
158 | from.sa.sa_family,0,0); | |
159 | } else { | |
bf28fc73 | 160 | uint32_t msgtype; |
7d31df0e IJ |
161 | if (cc->rbuf->size>12 /* prevents traffic amplification */ |
162 | && ((msgtype=get_uint32(cc->rbuf->start+8)) | |
bf28fc73 IJ |
163 | != LABEL_NAK)) { |
164 | uint32_t source,dest; | |
165 | /* Manufacture and send NAK packet */ | |
7d31df0e IJ |
166 | source=get_uint32(cc->rbuf->start); /* Us */ |
167 | dest=get_uint32(cc->rbuf->start+4); /* Them */ | |
168 | send_nak(&ca,source,dest,msgtype,cc->rbuf,"unwanted"); | |
bf28fc73 | 169 | } |
7d31df0e | 170 | BUF_FREE(cc->rbuf); |
2fe58dfd | 171 | } |
7d31df0e | 172 | BUF_ASSERT_FREE(cc->rbuf); |
56c8ed69 | 173 | } else { /* rv<=0 */ |
2d7478f7 | 174 | if (errno!=EINTR && !iswouldblock(errno)) |
c72d679d | 175 | udp_sock_experienced(0,uc,socks,us, 0,0, rv,errno); |
7d31df0e | 176 | BUF_FREE(cc->rbuf); |
2fe58dfd SE |
177 | } |
178 | } while (rv>=0); | |
179 | } | |
180 | } | |
181 | ||
2fe58dfd | 182 | static bool_t udp_sendmsg(void *commst, struct buffer_if *buf, |
a15faeb2 | 183 | const struct comm_addr *dest) |
2fe58dfd SE |
184 | { |
185 | struct udp *st=commst; | |
763e458f IJ |
186 | struct udpcommon *uc=&st->uc; |
187 | struct udpsocks *socks=&st->socks; | |
ff05a229 | 188 | uint8_t *sa; |
2fe58dfd | 189 | |
7d31df0e | 190 | if (uc->use_proxy) { |
56c8ed69 | 191 | struct udpsock *us=&socks->socks[0]; |
3abd18e8 | 192 | sa=buf_prepend(buf,8); |
a32d56fb IJ |
193 | if (dest->ia.sa.sa_family != AF_INET) { |
194 | Message(M_INFO, | |
195 | "udp: proxy means dropping outgoing non-IPv4 packet to %s\n", | |
196 | iaddr_to_string(&dest->ia)); | |
197 | return False; | |
198 | } | |
199 | memcpy(sa,&dest->ia.sin.sin_addr,4); | |
ff05a229 | 200 | memset(sa+4,0,4); |
a32d56fb | 201 | memcpy(sa+6,&dest->ia.sin.sin_port,2); |
2d7478f7 | 202 | int r=sendto(us->fd,sa,buf->size+8,0,&uc->proxy.sa, |
7d31df0e | 203 | iaddr_socklen(&uc->proxy)); |
6c5889e6 | 204 | udp_sock_experienced(0,uc,socks,us, &dest->ia,0, r,errno); |
3abd18e8 | 205 | buf_unprepend(buf,8); |
ff05a229 | 206 | } else { |
08b62a6c IJ |
207 | int i,r; |
208 | bool_t allunsupported=True; | |
56c8ed69 | 209 | int af=dest->ia.sa.sa_family; |
7d31df0e | 210 | for (i=0; i<socks->n_socks; i++) { |
56c8ed69 IJ |
211 | struct udpsock *us=&socks->socks[i]; |
212 | if (us->addr.sa.sa_family != af) | |
08b62a6c IJ |
213 | /* no point even trying */ |
214 | continue; | |
56c8ed69 | 215 | r=sendto(us->fd, buf->start, buf->size, 0, |
08b62a6c | 216 | &dest->ia.sa, iaddr_socklen(&dest->ia)); |
6c5889e6 | 217 | udp_sock_experienced(0,uc,socks,us, &dest->ia,af, r,errno); |
08b62a6c IJ |
218 | if (r>=0) return True; |
219 | if (!(errno==EAFNOSUPPORT || errno==ENETUNREACH)) | |
220 | /* who knows what that error means? */ | |
221 | allunsupported=False; | |
222 | } | |
223 | return !allunsupported; /* see doc for comm_sendmsg_fn in secnet.h */ | |
ff05a229 | 224 | } |
2fe58dfd SE |
225 | |
226 | return True; | |
227 | } | |
228 | ||
5f8b7a8e IJ |
229 | void udp_destroy_socket(struct udpcommon *uc, struct udpsock *us) |
230 | { | |
231 | if (us->fd>=0) { | |
232 | close(us->fd); | |
233 | us->fd=-1; | |
234 | } | |
235 | } | |
236 | ||
9c44ef13 IJ |
237 | #define FAIL_LG 0, cc->cl.description, &cc->loc, failmsgclass |
238 | #define FAIL(...) do{ \ | |
239 | lg_perror(FAIL_LG,errno,__VA_ARGS__); \ | |
240 | goto failed; \ | |
241 | }while(0) | |
242 | ||
243 | static bool_t record_socket_gotaddr(struct udpcommon *uc, struct udpsock *us, | |
244 | int failmsgclass) | |
245 | { | |
246 | struct commcommon *cc=&uc->cc; | |
247 | socklen_t salen=sizeof(us->addr); | |
248 | int r=getsockname(us->fd,&us->addr.sa,&salen); | |
249 | if (r) FAIL("getsockname()"); | |
250 | if (salen>sizeof(us->addr)) { errno=0; FAIL("getsockname() length"); } | |
251 | return True; | |
252 | ||
253 | failed: | |
254 | return False; | |
255 | } | |
256 | ||
257 | bool_t udp_import_socket(struct udpcommon *uc, struct udpsock *us, | |
258 | int failmsgclass, int fd) | |
259 | { | |
260 | FILLZERO(us->experienced); | |
261 | us->fd=fd; | |
262 | return record_socket_gotaddr(uc,us,failmsgclass); | |
263 | } | |
264 | ||
53f4e666 IJ |
265 | bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us, |
266 | int failmsgclass) | |
baa06aeb | 267 | { |
f164f167 | 268 | const union iaddr *addr=&us->addr; |
763e458f | 269 | struct commcommon *cc=&uc->cc; |
53f4e666 IJ |
270 | us->fd=-1; |
271 | ||
2d7478f7 | 272 | FILLZERO(us->experienced); |
08b62a6c | 273 | us->fd=socket(addr->sa.sa_family, SOCK_DGRAM, IPPROTO_UDP); |
53f4e666 | 274 | if (us->fd<0) FAIL("socket"); |
f54d5ada | 275 | setnonblock(us->fd); |
f164f167 | 276 | setcloexec(us->fd); |
08b62a6c IJ |
277 | #ifdef CONFIG_IPV6 |
278 | if (addr->sa.sa_family==AF_INET6) { | |
279 | int r; | |
280 | int optval=1; | |
281 | socklen_t optlen=sizeof(optval); | |
282 | r=setsockopt(us->fd,IPPROTO_IPV6,IPV6_V6ONLY,&optval,optlen); | |
53f4e666 | 283 | if (r) FAIL("setsockopt(,IPV6_V6ONLY,&1,)"); |
08b62a6c IJ |
284 | } |
285 | #endif | |
baa06aeb | 286 | |
7d31df0e | 287 | if (uc->authbind) { |
b2a56f7c SE |
288 | pid_t c; |
289 | int status; | |
eea14dc2 IJ |
290 | char desc[200]; |
291 | snprintf(desc,sizeof(desc),"authbind for %s: %s", | |
292 | iaddr_to_string(addr), uc->authbind); | |
b2a56f7c SE |
293 | |
294 | /* XXX this fork() and waitpid() business needs to be hidden | |
295 | in some system-specific library functions. */ | |
296 | c=fork(); | |
53f4e666 IJ |
297 | if (c==-1) |
298 | FAIL("fork() for authbind"); | |
b2a56f7c | 299 | if (c==0) { |
3ff31eda IJ |
300 | char *argv[5], addrstr[33], portstr[5]; |
301 | const char *addrfam; | |
302 | int port; | |
5e7a5e2d | 303 | afterfork(); |
f164f167 | 304 | switch (addr->sa.sa_family) { |
a32d56fb | 305 | case AF_INET: |
f164f167 | 306 | sprintf(addrstr,"%08lX",(long)addr->sin.sin_addr.s_addr); |
3ff31eda IJ |
307 | port=addr->sin.sin_port; |
308 | addrfam=NULL; | |
a32d56fb | 309 | break; |
3ff31eda IJ |
310 | #ifdef CONFIG_IPV6 |
311 | case AF_INET6: { | |
312 | int i; | |
313 | for (i=0; i<16; i++) | |
314 | sprintf(addrstr+i*2,"%02X",addr->sin6.sin6_addr.s6_addr[i]); | |
315 | port=addr->sin6.sin6_port; | |
316 | addrfam="6"; | |
317 | break; | |
318 | } | |
319 | #endif /*CONFIG_IPV6*/ | |
a32d56fb IJ |
320 | default: |
321 | fatal("udp (%s:%d): unsupported address family for authbind", | |
7d31df0e | 322 | cc->loc.file,cc->loc.line); |
a32d56fb | 323 | } |
3ff31eda | 324 | sprintf(portstr,"%04X",port); |
7d31df0e | 325 | argv[0]=uc->authbind; |
3b83c932 SE |
326 | argv[1]=addrstr; |
327 | argv[2]=portstr; | |
3ff31eda IJ |
328 | argv[3]=(char*)addrfam; |
329 | argv[4]=NULL; | |
f164f167 | 330 | dup2(us->fd,0); |
7d31df0e | 331 | execvp(uc->authbind,argv); |
3b83c932 | 332 | _exit(255); |
b2a56f7c | 333 | } |
3b83c932 SE |
334 | while (waitpid(c,&status,0)==-1) { |
335 | if (errno==EINTR) continue; | |
53f4e666 | 336 | FAIL("waitpid for authbind"); |
b2a56f7c | 337 | } |
4ac7fd3f | 338 | if (status) { |
313e4f0f IJ |
339 | if (WIFEXITED(status) && WEXITSTATUS(status)<127) { |
340 | int es=WEXITSTATUS(status); | |
341 | lg_perror(FAIL_LG,es, | |
eea14dc2 IJ |
342 | "%s exited with error exit status %d;" |
343 | " indicates error",desc,es); | |
313e4f0f | 344 | } else { |
eea14dc2 | 345 | lg_exitstatus(FAIL_LG,status,desc); |
313e4f0f | 346 | } |
53f4e666 | 347 | goto failed; |
3b83c932 | 348 | } |
b2a56f7c | 349 | } else { |
53f4e666 IJ |
350 | if (bind(us->fd, &addr->sa, iaddr_socklen(addr))!=0) |
351 | FAIL("bind (%s)",iaddr_to_string(addr)); | |
baa06aeb | 352 | } |
9c44ef13 IJ |
353 | |
354 | bool_t ok=record_socket_gotaddr(uc,us,failmsgclass); | |
355 | if (!ok) goto failed; | |
356 | ||
53f4e666 IJ |
357 | return True; |
358 | ||
359 | failed: | |
5f8b7a8e | 360 | udp_destroy_socket(uc,us); |
53f4e666 | 361 | return False; |
9c44ef13 | 362 | } |
53f4e666 IJ |
363 | |
364 | #undef FAIL | |
baa06aeb | 365 | |
c72d679d IJ |
366 | void udp_socks_register(struct udpcommon *uc, struct udpsocks *socks, |
367 | const char *desc) | |
f7af3192 IJ |
368 | { |
369 | socks->uc=uc; | |
c72d679d | 370 | socks->desc=desc; |
5c679ae0 IJ |
371 | socks->interest= |
372 | register_for_poll(socks,udp_socks_beforepoll,udp_socks_afterpoll,"udp"); | |
373 | } | |
374 | ||
375 | void udp_socks_deregister(struct udpcommon *uc, struct udpsocks *socks) | |
376 | { | |
377 | socks->uc=uc; | |
378 | deregister_for_poll(socks->interest); | |
f7af3192 IJ |
379 | } |
380 | ||
32654a31 IJ |
381 | void udp_socks_childpersist(struct udpcommon *uc, struct udpsocks *socks) |
382 | { | |
383 | int i; | |
384 | for (i=0; i<socks->n_socks; i++) | |
385 | udp_destroy_socket(uc,&socks->socks[i]); | |
386 | } | |
387 | ||
388 | static void udp_childpersist_hook(void *sst, uint32_t new_phase) | |
389 | { | |
390 | struct udp *st=sst; | |
391 | udp_socks_childpersist(&st->uc,&st->socks); | |
392 | } | |
393 | ||
f164f167 IJ |
394 | static void udp_phase_hook(void *sst, uint32_t new_phase) |
395 | { | |
396 | struct udp *st=sst; | |
763e458f | 397 | struct udpsocks *socks=&st->socks; |
f7af3192 | 398 | struct udpcommon *uc=&st->uc; |
08b62a6c | 399 | int i; |
b3877445 IJ |
400 | bool_t anydone=0; |
401 | ||
402 | for (i=0; i<socks->n_socks; i++) { | |
403 | bool_t required=st->addr_configured | |
404 | || (!anydone && i==socks->n_socks-1); | |
405 | anydone += udp_make_socket(uc,&socks->socks[i], | |
406 | required ? M_FATAL : M_WARNING); | |
407 | } | |
08b62a6c | 408 | |
c72d679d | 409 | udp_socks_register(uc,socks, uc->use_proxy ? "proxy" : "socket"); |
32654a31 IJ |
410 | |
411 | add_hook(PHASE_CHILDPERSIST,udp_childpersist_hook,st); | |
baa06aeb SE |
412 | } |
413 | ||
2fe58dfd SE |
414 | static list_t *udp_apply(closure_t *self, struct cloc loc, dict_t *context, |
415 | list_t *args) | |
416 | { | |
417 | struct udp *st; | |
08b62a6c | 418 | list_t *caddrl; |
ff05a229 SE |
419 | list_t *l; |
420 | uint32_t a; | |
08b62a6c | 421 | int i; |
2fe58dfd | 422 | |
763e458f IJ |
423 | COMM_APPLY(st,&st->uc.cc,udp_,"udp",loc); |
424 | COMM_APPLY_STANDARD(st,&st->uc.cc,"udp",args); | |
425 | UDP_APPLY_STANDARD(st,&st->uc,"udp"); | |
2fe58dfd | 426 | |
763e458f IJ |
427 | struct udpcommon *uc=&st->uc; |
428 | struct udpsocks *socks=&st->socks; | |
429 | struct commcommon *cc=&uc->cc; | |
08b62a6c IJ |
430 | |
431 | union iaddr defaultaddrs[] = { | |
432 | #ifdef CONFIG_IPV6 | |
433 | { .sin6 = { .sin6_family=AF_INET6, | |
763e458f | 434 | .sin6_port=htons(uc->port), |
08b62a6c IJ |
435 | .sin6_addr=IN6ADDR_ANY_INIT } }, |
436 | #endif | |
437 | { .sin = { .sin_family=AF_INET, | |
763e458f | 438 | .sin_port=htons(uc->port), |
08b62a6c IJ |
439 | .sin_addr= { .s_addr=INADDR_ANY } } } |
440 | }; | |
441 | ||
442 | caddrl=dict_lookup(d,"address"); | |
93910f6a IJ |
443 | st->addr_configured=!!caddrl; |
444 | socks->n_socks=st->addr_configured ? list_length(caddrl) | |
445 | : (int)ARRAY_SIZE(defaultaddrs); | |
7d31df0e IJ |
446 | if (socks->n_socks<=0 || socks->n_socks>UDP_MAX_SOCKETS) |
447 | cfgfatal(cc->loc,"udp","`address' must be 1..%d addresses", | |
448 | UDP_MAX_SOCKETS); | |
08b62a6c | 449 | |
7d31df0e IJ |
450 | for (i=0; i<socks->n_socks; i++) { |
451 | struct udpsock *us=&socks->socks[i]; | |
93910f6a | 452 | if (!st->addr_configured) { |
08b62a6c IJ |
453 | us->addr=defaultaddrs[i]; |
454 | } else { | |
763e458f | 455 | string_item_to_iaddr(list_elem(caddrl,i),uc->port,&us->addr,"udp"); |
08b62a6c IJ |
456 | } |
457 | us->fd=-1; | |
458 | } | |
459 | ||
ff05a229 SE |
460 | l=dict_lookup(d,"proxy"); |
461 | if (l) { | |
7d31df0e IJ |
462 | uc->use_proxy=True; |
463 | uc->proxy.sa.sa_family=AF_INET; | |
c649eafe IJ |
464 | item=list_elem(l,0); |
465 | if (!item || item->type!=t_string) { | |
7d31df0e | 466 | cfgfatal(cc->loc,"udp","proxy must supply ""addr"",port\n"); |
ff05a229 | 467 | } |
c649eafe | 468 | a=string_item_to_ipaddr(item,"proxy"); |
7d31df0e | 469 | uc->proxy.sin.sin_addr.s_addr=htonl(a); |
c649eafe IJ |
470 | item=list_elem(l,1); |
471 | if (!item || item->type!=t_number) { | |
7d31df0e | 472 | cfgfatal(cc->loc,"udp","proxy must supply ""addr"",port\n"); |
ff05a229 | 473 | } |
7d31df0e | 474 | uc->proxy.sin.sin_port=htons(item->data.number); |
ff05a229 | 475 | } |
2fe58dfd | 476 | |
7d31df0e | 477 | update_max_start_pad(&comm_max_start_pad, uc->use_proxy ? 8 : 0); |
3abd18e8 | 478 | |
baa06aeb | 479 | add_hook(PHASE_GETRESOURCES,udp_phase_hook,st); |
2fe58dfd | 480 | |
7d31df0e | 481 | return new_closure(&cc->cl); |
2fe58dfd SE |
482 | } |
483 | ||
2fe58dfd SE |
484 | void udp_module(dict_t *dict) |
485 | { | |
486 | add_closure(dict,"udp",udp_apply); | |
487 | } |