From dd0e6c383a9f03607f787f661a9591c89d2f49ea Mon Sep 17 00:00:00 2001 From: Kip Macy Date: Mon, 21 Jul 2008 00:49:34 +0000 Subject: [PATCH] Add accessor functions for socket fields. MFC after: 1 week --- sys/kern/uipc_socket.c | 139 +++++++++++++++++++++++++++++++++++++++++ sys/netinet/in_pcb.c | 14 +++++ sys/sys/socket.h | 37 +++++++++++ 3 files changed, 190 insertions(+) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index e5096b9d1d2f..58d112583861 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -3209,3 +3209,142 @@ sotoxsocket(struct socket *so, struct xsocket *xso) sbtoxsockbuf(&so->so_rcv, &xso->so_rcv); xso->so_uid = so->so_cred->cr_uid; } + + +/* + * Socket accessor functions to provide external consumers with + * a safe interface to socket state + * + */ + +void +so_listeners_apply_all(struct socket *so, void (*func)(struct socket *, void *), void *arg) +{ + + TAILQ_FOREACH(so, &so->so_comp, so_list) + func(so, arg); +} + +struct sockbuf * +so_sockbuf_rcv(struct socket *so) +{ + + return (&so->so_rcv); +} + +struct sockbuf * +so_sockbuf_snd(struct socket *so) +{ + + return (&so->so_snd); +} + +int +so_state_get(const struct socket *so) +{ + + return (so->so_state); +} + +void +so_state_set(struct socket *so, int val) +{ + + so->so_state = val; +} + +int +so_options_get(const struct socket *so) +{ + + return (so->so_options); +} + +void +so_options_set(struct socket *so, int val) +{ + + so->so_options = val; +} + +int +so_error_get(const struct socket *so) +{ + + return (so->so_error); +} + +void +so_error_set(struct socket *so, int val) +{ + + so->so_error = val; +} + +int +so_linger_get(const struct socket *so) +{ + + return (so->so_linger); +} + +void +so_linger_set(struct socket *so, int val) +{ + + so->so_linger = val; +} + +struct protosw * +so_protosw_get(const struct socket *so) +{ + + return (so->so_proto); +} + +void +so_protosw_set(struct socket *so, struct protosw *val) +{ + + so->so_proto = val; +} + +void +so_sorwakeup(struct socket *so) +{ + + sorwakeup(so); +} + +void +so_sowwakeup(struct socket *so) +{ + + sowwakeup(so); +} + +void +so_sorwakeup_locked(struct socket *so) +{ + + sorwakeup_locked(so); +} + +void +so_sowwakeup_locked(struct socket *so) +{ + + sowwakeup_locked(so); +} + +void +so_lock(struct socket *so) +{ + SOCK_LOCK(so); +} + +void +so_unlock(struct socket *so) +{ + SOCK_UNLOCK(so); +} diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 83e244ea07dc..10f22b3d4b5b 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -1308,6 +1308,20 @@ inp_4tuple_get(const struct inpcb *inp, uint32_t *laddr, uint16_t *lp, uint32_t *fp = inp->inp_fport; } +struct inpcb * +so_sotoinpcb(struct socket *so) +{ + + return (sotoinpcb(so)); +} + +struct tcpcb * +so_sototcpcb(struct socket *so) +{ + + return (sototcpcb(so)); +} + #ifdef DDB static void db_print_indent(int indent) diff --git a/sys/sys/socket.h b/sys/sys/socket.h index 7ed9c703c051..1d7998cea938 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -650,4 +650,41 @@ __END_DECLS #endif /* !_KERNEL */ +#ifdef _KERNEL +struct socket; + +struct tcpcb *so_sototcpcb(struct socket *so); +struct inpcb *so_sotoinpcb(struct socket *so); +struct sockbuf *so_sockbuf_snd(struct socket *); +struct sockbuf *so_sockbuf_rcv(struct socket *); + +int so_state_get(const struct socket *); +void so_state_set(struct socket *, int); + +int so_options_get(const struct socket *); +void so_options_set(struct socket *, int); + +int so_error_get(const struct socket *); +void so_error_set(struct socket *, int); + +int so_linger_get(const struct socket *); +void so_linger_set(struct socket *, int); + +struct protosw *so_protosw_get(const struct socket *); +void so_protosw_set(struct socket *, struct protosw *); + +void so_sorwakeup_locked(struct socket *so); +void so_sowwakeup_locked(struct socket *so); + +void so_sorwakeup(struct socket *so); +void so_sowwakeup(struct socket *so); + +void so_lock(struct socket *so); +void so_unlock(struct socket *so); + +void so_listeners_apply_all(struct socket *so, void (*func)(struct socket *, void *), void *arg); + +#endif + + #endif /* !_SYS_SOCKET_H_ */