Lines Matching defs:fwudp

63  * For fwudp all proxied UDP conversations share the same socket, so
64 * single fwudp multiplexes to several UDP pcbs.
66 * XXX: TODO: Currently pcbs point back directly to fwudp. It might
67 * make sense to introduce a per-pcb structure that points to fwudp
70 struct fwudp {
105 struct fwudp *next;
109 struct fwudp *fwudp_create(struct fwspec *);
111 /* poll manager callback for fwudp socket */
119 static void fwudp_pcb_forward_outbound(struct fwudp *, struct udp_pcb *, struct pbuf *);
125 struct fwudp *fwudp_list = NULL;
138 struct fwudp *fwudp;
140 fwudp = fwudp_create(fwspec);
141 if (fwudp == NULL) {
147 /* fwudp_create has put fwudp on the linked list */
154 struct fwudp *fwudp;
155 struct fwudp **pprev;
157 for (pprev = &fwudp_list; (fwudp = *pprev) != NULL; pprev = &fwudp->next) {
158 if (fwspec_equal(&fwudp->fwspec, fwspec)) {
159 *pprev = fwudp->next;
160 fwudp->next = NULL;
165 if (fwudp == NULL) {
172 pollmgr_del_slot(fwudp->pmhdl.slot);
173 fwudp->pmhdl.slot = -1;
175 /* let pending msg_send be processed before we delete fwudp */
176 proxy_lwip_post(&fwudp->msg_delete);
180 struct fwudp *
183 struct fwudp *fwudp;
192 fwudp = (struct fwudp *)malloc(sizeof(*fwudp));
193 if (fwudp == NULL) {
198 fwudp->pmhdl.callback = fwudp_pmgr_pump;
199 fwudp->pmhdl.data = (void *)fwudp;
200 fwudp->pmhdl.slot = -1;
202 fwudp->sock = sock;
203 fwudp->fwspec = *fwspec; /* struct copy */
208 memcpy(&fwudp->dst_addr.ip4, &dst4->sin_addr, sizeof(ip_addr_t));
209 fwudp->dst_port = htons(dst4->sin_port);
213 memcpy(&fwudp->dst_addr.ip6, &dst6->sin6_addr, sizeof(ip6_addr_t));
214 fwudp->dst_port = htons(dst6->sin6_port);
217 fwudp->inbuf.bufsize = 256; /* elements */
218 fwudp->inbuf.buf
219 = (struct fwudp_dgram *)calloc(fwudp->inbuf.bufsize,
221 if (fwudp->inbuf.buf == NULL) {
223 free(fwudp);
226 fwudp->inbuf.vacant = 0;
227 fwudp->inbuf.unsent = 0;
231 fwudp->MSG.type = TCPIP_MSG_CALLBACK_STATIC; \
232 fwudp->MSG.sem = NULL; \
233 fwudp->MSG.msg.cb.function = FUNC; \
234 fwudp->MSG.msg.cb.ctx = (void *)fwudp; \
242 status = pollmgr_add(&fwudp->pmhdl, fwudp->sock, POLLIN);
245 free(fwudp->inbuf.buf);
246 free(fwudp);
250 fwudp->next = fwudp_list;
251 fwudp_list = fwudp;
253 return fwudp;
258 * Poll manager callaback for fwudp::sock
263 struct fwudp *fwudp;
273 fwudp = (struct fwudp *)handler->data;
275 LWIP_ASSERT1(fwudp != NULL);
276 LWIP_ASSERT1(fd == fwudp->sock);
281 nread = recvfrom(fwudp->sock, pollmgr_udpbuf, sizeof(pollmgr_udpbuf), 0,
289 lim = fwudp->inbuf.unsent;
291 lim = fwudp->inbuf.bufsize - 1; /* guard slot at the end */
297 beg = fwudp->inbuf.vacant;
303 dgram = &fwudp->inbuf.buf[beg];
336 if (beg == fwudp->inbuf.bufsize) {
339 fwudp->inbuf.vacant = beg;
341 proxy_lwip_post(&fwudp->msg_send);
348 * Lwip thread callback invoked via fwudp::msg_send
353 struct fwudp *fwudp = (struct fwudp *)arg;
360 idx = fwudp->inbuf.unsent;
362 if (idx == fwudp->inbuf.vacant) {
368 dgram = fwudp->inbuf.buf[idx]; /* struct copy */
370 fwudp->inbuf.buf[idx].p = NULL;
372 if (++idx == fwudp->inbuf.bufsize) {
375 fwudp->inbuf.unsent = idx;
378 isv6 = (fwudp->fwspec.sdom == PF_INET6);
382 && pcb->remote_port == fwudp->dst_port
383 && ipX_addr_cmp(isv6, &fwudp->dst_addr, &pcb->remote_ip)
421 ipX_addr_set(isv6, &pcb->remote_ip, &fwudp->dst_addr);
422 pcb->remote_port = fwudp->dst_port;
425 udp_recv(pcb, fwudp_pcb_recv, fwudp);
446 struct fwudp *fwudp = (struct fwudp *)arg;
451 LWIP_ASSERT1(fwudp != NULL);
454 DPRINTF(("%s: pcb %p (fwudp %p); sock %d: expired\n",
455 __func__, (void *)pcb, (void *)fwudp, fwudp->sock));
456 /* NB: fwudp is "global" and not deleted */
462 fwudp_pcb_forward_outbound(fwudp, pcb, p);
469 * - s/pxudp/fwudp/g
474 fwudp_pcb_forward_outbound(struct fwudp *fwudp, struct udp_pcb *pcb,
485 if (fwudp->fwspec.sdom == PF_INET) {
505 proxy_sendto(fwudp->sock, p, &peer, namelen);
511 * Lwip thread callback invoked via fwudp::msg_delete
516 struct fwudp *fwudp = (struct fwudp *)arg;
520 LWIP_ASSERT1(fwudp->inbuf.unsent == fwudp->inbuf.vacant);
525 if (pcb->recv_arg != fwudp) {
537 closesocket(fwudp->sock);
538 free(fwudp->inbuf.buf);
539 free(fwudp);