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