diff options
author | Sridhar Samudrala <sri@us.ibm.com> | 2006-08-07 23:57:31 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-09-22 17:54:05 -0400 |
commit | ac5a488ef252ed673cb067843e411f8cc43f7ab9 (patch) | |
tree | e607478560ed050723fe5e578dc5ede37bedfa93 /net/socket.c | |
parent | b63bbc5006a0a62fabc81c4f77e95f16ff16f340 (diff) |
[NET]: Round out in-kernel sockets API
This patch implements wrapper functions that provide a convenient way
to access the sockets API for in-kernel users like sunrpc, cifs &
ocfs2 etc and any future users.
Signed-off-by: Sridhar Samudrala <sri@us.ibm.com>
Acked-by: James Morris <jmorris@namei.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/socket.c')
-rw-r--r-- | net/socket.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/net/socket.c b/net/socket.c index 6756e57e1ff0..2eaebf934a1a 100644 --- a/net/socket.c +++ b/net/socket.c | |||
@@ -2170,6 +2170,109 @@ static long compat_sock_ioctl(struct file *file, unsigned cmd, | |||
2170 | } | 2170 | } |
2171 | #endif | 2171 | #endif |
2172 | 2172 | ||
2173 | int kernel_bind(struct socket *sock, struct sockaddr *addr, int addrlen) | ||
2174 | { | ||
2175 | return sock->ops->bind(sock, addr, addrlen); | ||
2176 | } | ||
2177 | |||
2178 | int kernel_listen(struct socket *sock, int backlog) | ||
2179 | { | ||
2180 | return sock->ops->listen(sock, backlog); | ||
2181 | } | ||
2182 | |||
2183 | int kernel_accept(struct socket *sock, struct socket **newsock, int flags) | ||
2184 | { | ||
2185 | struct sock *sk = sock->sk; | ||
2186 | int err; | ||
2187 | |||
2188 | err = sock_create_lite(sk->sk_family, sk->sk_type, sk->sk_protocol, | ||
2189 | newsock); | ||
2190 | if (err < 0) | ||
2191 | goto done; | ||
2192 | |||
2193 | err = sock->ops->accept(sock, *newsock, flags); | ||
2194 | if (err < 0) { | ||
2195 | sock_release(*newsock); | ||
2196 | goto done; | ||
2197 | } | ||
2198 | |||
2199 | (*newsock)->ops = sock->ops; | ||
2200 | |||
2201 | done: | ||
2202 | return err; | ||
2203 | } | ||
2204 | |||
2205 | int kernel_connect(struct socket *sock, struct sockaddr *addr, int addrlen, | ||
2206 | int flags) | ||
2207 | { | ||
2208 | return sock->ops->connect(sock, addr, addrlen, flags); | ||
2209 | } | ||
2210 | |||
2211 | int kernel_getsockname(struct socket *sock, struct sockaddr *addr, | ||
2212 | int *addrlen) | ||
2213 | { | ||
2214 | return sock->ops->getname(sock, addr, addrlen, 0); | ||
2215 | } | ||
2216 | |||
2217 | int kernel_getpeername(struct socket *sock, struct sockaddr *addr, | ||
2218 | int *addrlen) | ||
2219 | { | ||
2220 | return sock->ops->getname(sock, addr, addrlen, 1); | ||
2221 | } | ||
2222 | |||
2223 | int kernel_getsockopt(struct socket *sock, int level, int optname, | ||
2224 | char *optval, int *optlen) | ||
2225 | { | ||
2226 | mm_segment_t oldfs = get_fs(); | ||
2227 | int err; | ||
2228 | |||
2229 | set_fs(KERNEL_DS); | ||
2230 | if (level == SOL_SOCKET) | ||
2231 | err = sock_getsockopt(sock, level, optname, optval, optlen); | ||
2232 | else | ||
2233 | err = sock->ops->getsockopt(sock, level, optname, optval, | ||
2234 | optlen); | ||
2235 | set_fs(oldfs); | ||
2236 | return err; | ||
2237 | } | ||
2238 | |||
2239 | int kernel_setsockopt(struct socket *sock, int level, int optname, | ||
2240 | char *optval, int optlen) | ||
2241 | { | ||
2242 | mm_segment_t oldfs = get_fs(); | ||
2243 | int err; | ||
2244 | |||
2245 | set_fs(KERNEL_DS); | ||
2246 | if (level == SOL_SOCKET) | ||
2247 | err = sock_setsockopt(sock, level, optname, optval, optlen); | ||
2248 | else | ||
2249 | err = sock->ops->setsockopt(sock, level, optname, optval, | ||
2250 | optlen); | ||
2251 | set_fs(oldfs); | ||
2252 | return err; | ||
2253 | } | ||
2254 | |||
2255 | int kernel_sendpage(struct socket *sock, struct page *page, int offset, | ||
2256 | size_t size, int flags) | ||
2257 | { | ||
2258 | if (sock->ops->sendpage) | ||
2259 | return sock->ops->sendpage(sock, page, offset, size, flags); | ||
2260 | |||
2261 | return sock_no_sendpage(sock, page, offset, size, flags); | ||
2262 | } | ||
2263 | |||
2264 | int kernel_sock_ioctl(struct socket *sock, int cmd, unsigned long arg) | ||
2265 | { | ||
2266 | mm_segment_t oldfs = get_fs(); | ||
2267 | int err; | ||
2268 | |||
2269 | set_fs(KERNEL_DS); | ||
2270 | err = sock->ops->ioctl(sock, cmd, arg); | ||
2271 | set_fs(oldfs); | ||
2272 | |||
2273 | return err; | ||
2274 | } | ||
2275 | |||
2173 | /* ABI emulation layers need these two */ | 2276 | /* ABI emulation layers need these two */ |
2174 | EXPORT_SYMBOL(move_addr_to_kernel); | 2277 | EXPORT_SYMBOL(move_addr_to_kernel); |
2175 | EXPORT_SYMBOL(move_addr_to_user); | 2278 | EXPORT_SYMBOL(move_addr_to_user); |
@@ -2186,3 +2289,13 @@ EXPORT_SYMBOL(sock_wake_async); | |||
2186 | EXPORT_SYMBOL(sockfd_lookup); | 2289 | EXPORT_SYMBOL(sockfd_lookup); |
2187 | EXPORT_SYMBOL(kernel_sendmsg); | 2290 | EXPORT_SYMBOL(kernel_sendmsg); |
2188 | EXPORT_SYMBOL(kernel_recvmsg); | 2291 | EXPORT_SYMBOL(kernel_recvmsg); |
2292 | EXPORT_SYMBOL(kernel_bind); | ||
2293 | EXPORT_SYMBOL(kernel_listen); | ||
2294 | EXPORT_SYMBOL(kernel_accept); | ||
2295 | EXPORT_SYMBOL(kernel_connect); | ||
2296 | EXPORT_SYMBOL(kernel_getsockname); | ||
2297 | EXPORT_SYMBOL(kernel_getpeername); | ||
2298 | EXPORT_SYMBOL(kernel_getsockopt); | ||
2299 | EXPORT_SYMBOL(kernel_setsockopt); | ||
2300 | EXPORT_SYMBOL(kernel_sendpage); | ||
2301 | EXPORT_SYMBOL(kernel_sock_ioctl); | ||