Skip to content

Commit

Permalink
pstream: Add set_dscp method.
Browse files Browse the repository at this point in the history
Introduce set_dscp method to pstream.
This will be used by dynamic dscp change of listening socket.

Signed-off-by: Isaku Yamahata <[email protected]>
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
Isaku Yamahata authored and blp committed Sep 27, 2012
1 parent 6b9c1ea commit f89b7ce
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 5 deletions.
16 changes: 15 additions & 1 deletion lib/stream-fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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. */
Expand Down
1 change: 1 addition & 0 deletions lib/stream-fd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions lib/stream-provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 8 additions & 0 deletions lib/stream-ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,13 +862,21 @@ 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,
pssl_open,
pssl_close,
pssl_accept,
pssl_wait,
pssl_set_dscp,
};

/*
Expand Down
6 changes: 4 additions & 2 deletions lib/stream-tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -142,6 +143,7 @@ const struct pstream_class ptcp_pstream_class = {
ptcp_open,
NULL,
NULL,
NULL
NULL,
NULL,
};

5 changes: 3 additions & 2 deletions lib/stream-unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -118,6 +118,7 @@ const struct pstream_class punix_pstream_class = {
punix_open,
NULL,
NULL,
NULL
NULL,
NULL,
};

9 changes: 9 additions & 0 deletions lib/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

Expand Down

0 comments on commit f89b7ce

Please sign in to comment.