#include <netinet/in.h>
#include <arpa/inet.h>
#include "util.h"
+#include "magic.h"
#include "unaligned.h"
#include "ipaddr.h"
#include "magic.h"
fromlen=sizeof(from);
BUF_ASSERT_FREE(st->rbuf);
BUF_ALLOC(st->rbuf,"udp_afterpoll");
+ buffer_init(st->rbuf,calculate_max_start_pad());
rv=recvfrom(st->fd, st->rbuf->start, st->rbuf->len, 0,
(struct sockaddr *)&from, &fromlen);
if (rv>0) {
buf_unprepend(st->rbuf,2);
memcpy(&from.sin_port,buf_unprepend(st->rbuf,2),2);
}
+ struct comm_addr ca;
+ FILLZERO(ca);
+ ca.comm=&st->ops;
+ ca.sin=from;
done=False;
for (n=st->notify; n; n=n->next) {
- struct comm_addr ca;
- FILLZERO(ca);
- ca.comm=&st->ops;
- ca.sin=from;
if (n->fn(n->state, st->rbuf, &ca)) {
done=True;
break;
/* Manufacture and send NAK packet */
source=get_uint32(st->rbuf->start); /* Us */
dest=get_uint32(st->rbuf->start+4); /* Them */
- Message(M_INFO,"udp (port %d, peer %s):"
- " %08"PRIx32"<-%08"PRIx32": %08"PRIx32":"
- " unwanted/incorrect, sending NAK\n",
- st->port, saddr_to_string(&from),
- dest, source, msgtype);
- buffer_init(st->rbuf,0);
- buf_append_uint32(st->rbuf,dest);
- buf_append_uint32(st->rbuf,source);
- buf_append_uint32(st->rbuf,LABEL_NAK);
- sendto(st->fd, st->rbuf->start, st->rbuf->size, 0,
- (struct sockaddr *)&from, sizeof(from));
+ send_nak(&ca,source,dest,msgtype,st->rbuf,"unwanted");
}
BUF_FREE(st->rbuf);
}
uint8_t *sa;
if (st->use_proxy) {
- sa=buf->start-8;
+ sa=buf_prepend(buf,8);
memcpy(sa,&dest->sin.sin_addr,4);
memset(sa+4,0,4);
memcpy(sa+6,&dest->sin.sin_port,2);
sendto(st->fd,sa,buf->size+8,0,(struct sockaddr *)&st->proxy,
sizeof(st->proxy));
+ buf_unprepend(buf,8);
} else {
sendto(st->fd, buf->start, buf->size, 0,
(struct sockaddr *)&dest->sin, sizeof(dest->sin));
st->cl.apply=NULL;
st->cl.interface=&st->ops;
st->ops.st=st;
- st->ops.min_start_pad=0;
- st->ops.min_end_pad=0;
st->ops.request_notify=request_notify;
st->ops.release_notify=release_notify;
st->ops.sendmsg=udp_sendmsg;
cfgfatal(st->loc,"udp","proxy must supply ""addr"",port\n");
}
st->proxy.sin_port=htons(i->data.number);
- st->ops.min_start_pad=8;
}
+ update_max_start_pad(&comm_max_start_pad, st->use_proxy ? 8 : 0);
+
add_hook(PHASE_GETRESOURCES,udp_phase_hook,st);
return new_closure(&st->cl);