* and net.visibleipv4 are unspecified the address of the hub
* connection is used. */
{CONF_VAR_STRING, "publicif", {.str = L""}},
- /* Diffserv should be supported on IPv4, too, but I don't know the
- * API to do that. */
/** The Diffserv value to use on IPv6 connections when the
* minimize cost TOS value is used (see the TOS VALUES
* section). */
* minimize delay TOS value is used (see the TOS VALUES
* section). */
{CONF_VAR_INT, "diffserv-mindelay", {.num = 0}},
+ /** If enabled, the IP TOS interface will be used to set Diffserv
+ * codepoints on IPv4 sockets, by shifting the DSCP value two bits
+ * to the left (remember, the DSCP field in the IPv4 header is
+ * defined as the 6 uppermost bits of the TOS field, the lower two
+ * being left for ECN). This may only work on Linux. */
+ {CONF_VAR_BOOL, "dscp-tos", {.num = 0}},
{CONF_VAR_END}
};
new->refcount = 1;
new->state = -1;
new->dgram = dgram;
+ new->maxbuf = 65536;
numsocks++;
return(new);
}
}
}
-static void sockflush(struct ufd *ufd)
+static int sockflush(struct ufd *ufd)
{
int ret;
struct dgrambuf *dbuf;
int dgram;
- if((dgram = ufddgram(ufd)) < 0)
- return;
+ if((dgram = ufddgram(ufd)) < 0) {
+ errno = EBADFD;
+ return(-1);
+ }
if(dgram) {
dbuf = sockgetdgbuf(ufd->sk);
sendto(ufd->fd, dbuf->data, dbuf->size, MSG_DONTWAIT | MSG_NOSIGNAL, dbuf->addr, dbuf->addrlen);
ret = send(ufd->fd, ufd->sk->buf.s.buf, ufd->sk->buf.s.datasize, MSG_DONTWAIT | MSG_NOSIGNAL);
else
ret = write(ufd->fd, ufd->sk->buf.s.buf, ufd->sk->buf.s.datasize);
- if(ret < 0) {
- /* For now, assume transient error, since
- * the socket is polled for errors */
- return;
- }
+ if(ret < 0)
+ return(-1);
if(ret > 0) {
memmove(ufd->sk->buf.s.buf, ((char *)ufd->sk->buf.s.buf) + ret, ufd->sk->buf.s.datasize -= ret);
sockread(ufd->sk);
}
}
+ return(0);
}
void closesock(struct socket *sk)
return(ret);
}
-size_t sockqueuesize(struct socket *sk)
+/* size_t sockqueuesize(struct socket *sk) */
+/* { */
+/* return(sockgetdatalen(sk->back)); */
+/* } */
+
+ssize_t sockqueueleft(struct socket *sk)
{
- return(sockgetdatalen(sk->back));
+ return(sk->back->maxbuf - sockgetdatalen(sk->back));
}
/*
nsc = sc->n;
if(sc->s->conncb != NULL)
sc->s->conncb(sc->s, 0, sc->s->data);
+ putsock(sc->s);
free(sc);
}
for(sc = rbatch, rbatch = NULL; sc; sc = nsc) {
sc->s->errcb(sc->s, 0, sc->s->data);
sc->s->eos = 2;
}
+ putsock(sc->s);
free(sc);
}
for(sc = wbatch, wbatch = NULL; sc; sc = nsc) {
nsc = sc->n;
if(sc->s->writecb != NULL)
sc->s->writecb(sc->s, sc->s->data);
+ putsock(sc->s);
free(sc);
}
}
for(ufd = ufds; ufd != NULL; ufd = next) {
next = ufd->next;
- if(ufd->sk && (sockgetdatalen(ufd->sk) == 0)) {
+ if(ufd->sk && ((ufd->fd < 0) || (sockgetdatalen(ufd->sk) == 0))) {
if(ufd->sk->eos == 1) {
ufd->sk->eos = 2;
closeufd(ufd);
for(maxfd = 0, ufd = ufds; ufd != NULL; ufd = ufd->next) {
if(ufd->fd < 0)
continue;
- if(!ufd->ignread)
+ if(!ufd->ignread && ((ufd->sk == NULL) || (sockqueueleft(ufd->sk) > 0)))
FD_SET(ufd->fd, &rfds);
if(ufd->sk != NULL) {
if(sockgetdatalen(ufd->sk) > 0)
sockrecv(ufd);
if(ufd->fd == -1)
continue;
- if(FD_ISSET(ufd->fd, &wfds))
- sockflush(ufd);
+ if(FD_ISSET(ufd->fd, &wfds)) {
+ if(sockflush(ufd)) {
+ sockerror(ufd->sk, errno);
+ closeufd(ufd);
+ continue;
+ }
+ }
}
}
}
{
int buf;
struct ufd *ufd;
+ int dscp2tos;
ufd = getskufd(sk);
if(ufd->type != UFD_SOCK) {
return(0); /* Unix sockets are always perfect. :) */
if(ufd->d.s.family == AF_INET)
{
+ dscp2tos = confgetint("net", "dscp-tos");
switch(tos)
{
case 0:
buf = 0;
break;
case SOCK_TOS_MINCOST:
- buf = 0x02;
+ if(dscp2tos)
+ buf = confgetint("net", "diffserv-mincost") << 2;
+ else
+ buf = 0x02;
break;
case SOCK_TOS_MAXREL:
- buf = 0x04;
+ if(dscp2tos)
+ buf = confgetint("net", "diffserv-maxrel") << 2;
+ else
+ buf = 0x04;
break;
case SOCK_TOS_MAXTP:
- buf = 0x08;
+ if(dscp2tos)
+ buf = confgetint("net", "diffserv-maxtp") << 2;
+ else
+ buf = 0x08;
break;
case SOCK_TOS_MINDELAY:
- buf = 0x10;
+ if(dscp2tos)
+ buf = confgetint("net", "diffserv-mindelay") << 2;
+ else
+ buf = 0x10;
break;
default:
flog(LOG_WARNING, "attempted to set unknown TOS value %i to IPv4 sock", tos);
errno = EOPNOTSUPP;
return(-1);
}
- if(ufd1->d.s.family != ufd2->d.s.family)
+ if(ufd1->d.l.family != ufd2->d.s.family)
{
- flog(LOG_ERR, "using lstgetremotename2 with sockets of differing family: %i %i", ufd1->d.s.family, ufd2->d.s.family);
+ flog(LOG_ERR, "using lstgetremotename2 with sockets of differing family: %i %i", ufd1->d.l.family, ufd2->d.s.family);
return(-1);
}
if(getremotename(ufd1->fd, &name1, &len1))
return(0);
}
-void sockblock(struct socket *sk, int block)
-{
- struct ufd *ufd;
+/* void sockblock(struct socket *sk, int block) */
+/* { */
+/* struct ufd *ufd; */
- ufd = getskufd(sk);
- ufd->ignread = block;
-}
+/* ufd = getskufd(sk); */
+/* ufd->ignread = block; */
+/* } */
int sockfamily(struct socket *sk)
{