From: Isaku Yamahata Date: Thu, 27 Sep 2012 02:18:16 +0000 (+0900) Subject: pstream: Add set_dscp method. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f89b7ce502441c9b71ac469846049ecacabcd888;p=openvswitch pstream: Add set_dscp method. Introduce set_dscp method to pstream. This will be used by dynamic dscp change of listening socket. Signed-off-by: Isaku Yamahata Signed-off-by: Ben Pfaff --- diff --git a/lib/stream-fd.c b/lib/stream-fd.c index 6b782ec2..f7e1234a 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 80269538..8b8b48f3 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 9e91d615..b39dcf01 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 4a9dd4f6..0ca5b18d 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 97492937..05601e19 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 dde59968..4feefdfd 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 2c7bfc3a..2ee5731e 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 8ed0ff58..d2f2ebb7 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. */