Introduce set_dscp method to pstream.
This will be used by dynamic dscp change of listening socket.
Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
Signed-off-by: Ben Pfaff <blp@nicira.com>
int fd;
int (*accept_cb)(int fd, const struct sockaddr *, size_t sa_len,
struct stream **);
+ int (*set_dscp_cb)(int fd, uint8_t dscp);
char *unlink_path;
};
new_fd_pstream(const char *name, int fd,
int (*accept_cb)(int fd, const struct sockaddr *sa,
size_t sa_len, struct stream **streamp),
+ int (*set_dscp_cb)(int fd, uint8_t dscp),
char *unlink_path, struct pstream **pstreamp)
{
struct fd_pstream *ps = xmalloc(sizeof *ps);
pstream_init(&ps->pstream, &fd_pstream_class, name);
ps->fd = fd;
ps->accept_cb = accept_cb;
+ ps->set_dscp_cb = set_dscp_cb;
ps->unlink_path = unlink_path;
*pstreamp = &ps->pstream;
return 0;
poll_fd_wait(ps->fd, POLLIN);
}
+static int
+pfd_set_dscp(struct pstream *pstream, uint8_t dscp)
+{
+ struct fd_pstream *ps = fd_pstream_cast(pstream);
+ if (ps->set_dscp_cb) {
+ return ps->set_dscp_cb(ps->fd, dscp);
+ }
+ return 0;
+}
+
static struct pstream_class fd_pstream_class = {
"pstream",
false,
NULL,
pfd_close,
pfd_accept,
- pfd_wait
+ pfd_wait,
+ pfd_set_dscp,
};
\f
/* Helper functions. */
int new_fd_pstream(const char *name, int fd,
int (*accept_cb)(int fd, const struct sockaddr *,
size_t sa_len, struct stream **),
+ int (*set_dscp_cb)(int fd, uint8_t dscp),
char *unlink_path,
struct pstream **pstreamp);
/* Arranges for the poll loop to wake up when a connection is ready to be
* accepted on 'pstream'. */
void (*wait)(struct pstream *pstream);
+
+ /* Set DSCP value of the listening socket. */
+ int (*set_dscp)(struct pstream *pstream, uint8_t dscp);
};
/* Active and passive stream classes. */
poll_fd_wait(pssl->fd, POLLIN);
}
+static int
+pssl_set_dscp(struct pstream *pstream, uint8_t dscp)
+{
+ struct pssl_pstream *pssl = pssl_pstream_cast(pstream);
+ return set_dscp(pssl->fd, dscp);
+}
+
const struct pstream_class pssl_pstream_class = {
"pssl",
true,
pssl_close,
pssl_accept,
pssl_wait,
+ pssl_set_dscp,
};
\f
/*
sprintf(bound_name, "ptcp:%"PRIu16":"IP_FMT,
ntohs(sin.sin_port), IP_ARGS(&sin.sin_addr.s_addr));
- return new_fd_pstream(bound_name, fd, ptcp_accept, NULL, pstreamp);
+ return new_fd_pstream(bound_name, fd, ptcp_accept, set_dscp, NULL,
+ pstreamp);
}
static int
ptcp_open,
NULL,
NULL,
- NULL
+ NULL,
+ NULL,
};
return error;
}
- return new_fd_pstream(name, fd, punix_accept,
+ return new_fd_pstream(name, fd, punix_accept, NULL,
xstrdup(suffix), pstreamp);
}
punix_open,
NULL,
NULL,
- NULL
+ NULL,
+ NULL,
};
{
(pstream->class->wait)(pstream);
}
+
+int
+pstream_set_dscp(struct pstream *pstream, uint8_t dscp)
+{
+ if (pstream->class->set_dscp) {
+ return pstream->class->set_dscp(pstream, dscp);
+ }
+ return 0;
+}
\f
/* Initializes 'stream' as a new stream named 'name', implemented via 'class'.
* The initial connection status, supplied as 'connect_status', is interpreted
int pstream_accept(struct pstream *, struct stream **);
int pstream_accept_block(struct pstream *, struct stream **);
void pstream_wait(struct pstream *);
+int pstream_set_dscp(struct pstream *, uint8_t dscp);
\f
/* Convenience functions. */