[ovs-dev] [PATCH v3 1/2] lib/pstream: add set_dscp method
Isaku Yamahata
yamahata at valinux.co.jp
Thu Sep 27 02:18:16 UTC 2012
Introduce set_dscp method to pstream.
This will be used by dynamic dscp change of listening socket.
Signed-off-by: Isaku Yamahata <yamahata at valinux.co.jp>
---
Changes v2 -> v3:
- eliminated warning
> cc1: warnings being treated as errors
> ../lib/stream.c: In function ¡Æpstream_set_dscp¡Ç:
> ../lib/stream.c:623: error: control reaches end of non-void function
---
lib/stream-fd.c | 16 +++++++++++++++-
lib/stream-fd.h | 1 +
lib/stream-provider.h | 3 +++
lib/stream-ssl.c | 8 ++++++++
lib/stream-tcp.c | 6 ++++--
lib/stream-unix.c | 5 +++--
lib/stream.c | 9 +++++++++
lib/stream.h | 1 +
8 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/lib/stream-fd.c b/lib/stream-fd.c
index 6b782ec..f7e1234 100644
--- a/lib/stream-fd.c
+++ b/lib/stream-fd.c
@@ -169,6 +169,7 @@ struct fd_pstream
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;
};
@@ -199,12 +200,14 @@ int
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;
@@ -254,13 +257,24 @@ pfd_wait(struct pstream *pstream)
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,
};
/* Helper functions. */
diff --git a/lib/stream-fd.h b/lib/stream-fd.h
index 8026953..8b8b48f 100644
--- a/lib/stream-fd.h
+++ b/lib/stream-fd.h
@@ -30,6 +30,7 @@ int new_fd_stream(const char *name, int fd, int connect_status,
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);
diff --git a/lib/stream-provider.h b/lib/stream-provider.h
index 9e91d61..b39dcf0 100644
--- a/lib/stream-provider.h
+++ b/lib/stream-provider.h
@@ -190,6 +190,9 @@ struct pstream_class {
/* 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. */
diff --git a/lib/stream-ssl.c b/lib/stream-ssl.c
index 4a9dd4f..0ca5b18 100644
--- a/lib/stream-ssl.c
+++ b/lib/stream-ssl.c
@@ -862,6 +862,13 @@ pssl_wait(struct pstream *pstream)
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,
@@ -869,6 +876,7 @@ const struct pstream_class pssl_pstream_class = {
pssl_close,
pssl_accept,
pssl_wait,
+ pssl_set_dscp,
};
/*
diff --git a/lib/stream-tcp.c b/lib/stream-tcp.c
index 9749293..05601e1 100644
--- a/lib/stream-tcp.c
+++ b/lib/stream-tcp.c
@@ -117,7 +117,8 @@ ptcp_open(const char *name OVS_UNUSED, char *suffix, struct pstream **pstreamp,
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
@@ -142,6 +143,7 @@ const struct pstream_class ptcp_pstream_class = {
ptcp_open,
NULL,
NULL,
- NULL
+ NULL,
+ NULL,
};
diff --git a/lib/stream-unix.c b/lib/stream-unix.c
index dde5996..4feefdf 100644
--- a/lib/stream-unix.c
+++ b/lib/stream-unix.c
@@ -92,7 +92,7 @@ punix_open(const char *name OVS_UNUSED, char *suffix,
return error;
}
- return new_fd_pstream(name, fd, punix_accept,
+ return new_fd_pstream(name, fd, punix_accept, NULL,
xstrdup(suffix), pstreamp);
}
@@ -118,6 +118,7 @@ const struct pstream_class punix_pstream_class = {
punix_open,
NULL,
NULL,
- NULL
+ NULL,
+ NULL,
};
diff --git a/lib/stream.c b/lib/stream.c
index 2c7bfc3..2ee5731 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -613,6 +613,15 @@ pstream_wait(struct pstream *pstream)
{
(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;
+}
/* Initializes 'stream' as a new stream named 'name', implemented via 'class'.
* The initial connection status, supplied as 'connect_status', is interpreted
diff --git a/lib/stream.h b/lib/stream.h
index 8ed0ff5..d2f2ebb 100644
--- a/lib/stream.h
+++ b/lib/stream.h
@@ -65,6 +65,7 @@ void pstream_close(struct pstream *);
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);
/* Convenience functions. */
--
1.7.1.1
More information about the dev
mailing list