xref: /freebsd/sys/compat/linuxkpi/common/include/linux/net.h (revision 8e7baabc9fe7b5d5afe5df8ca9bcf60b5e1a2bc0)
18d59ecb2SHans Petter Selasky /*-
28d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Isilon Systems, Inc.
38d59ecb2SHans Petter Selasky  * Copyright (c) 2010 iX Systems, Inc.
48d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Panasas, Inc.
58d59ecb2SHans Petter Selasky  * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
68d59ecb2SHans Petter Selasky  * All rights reserved.
78d59ecb2SHans Petter Selasky  *
88d59ecb2SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
98d59ecb2SHans Petter Selasky  * modification, are permitted provided that the following conditions
108d59ecb2SHans Petter Selasky  * are met:
118d59ecb2SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
128d59ecb2SHans Petter Selasky  *    notice unmodified, this list of conditions, and the following
138d59ecb2SHans Petter Selasky  *    disclaimer.
148d59ecb2SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
158d59ecb2SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
168d59ecb2SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
178d59ecb2SHans Petter Selasky  *
188d59ecb2SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198d59ecb2SHans Petter Selasky  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208d59ecb2SHans Petter Selasky  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218d59ecb2SHans Petter Selasky  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228d59ecb2SHans Petter Selasky  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238d59ecb2SHans Petter Selasky  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248d59ecb2SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258d59ecb2SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268d59ecb2SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278d59ecb2SHans Petter Selasky  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288d59ecb2SHans Petter Selasky  *
298d59ecb2SHans Petter Selasky  * $FreeBSD$
308d59ecb2SHans Petter Selasky  */
318d59ecb2SHans Petter Selasky #ifndef	_LINUX_NET_H_
328d59ecb2SHans Petter Selasky #define	_LINUX_NET_H_
338d59ecb2SHans Petter Selasky 
34*8e7baabcSHans Petter Selasky #include <sys/types.h>
35*8e7baabcSHans Petter Selasky #include <sys/malloc.h>
36*8e7baabcSHans Petter Selasky #include <sys/proc.h>
378d59ecb2SHans Petter Selasky #include <sys/protosw.h>
388d59ecb2SHans Petter Selasky #include <sys/socket.h>
398d59ecb2SHans Petter Selasky #include <sys/socketvar.h>
40*8e7baabcSHans Petter Selasky #include <sys/errno.h>
418d59ecb2SHans Petter Selasky 
428d59ecb2SHans Petter Selasky static inline int
438d59ecb2SHans Petter Selasky sock_create_kern(int family, int type, int proto, struct socket **res)
448d59ecb2SHans Petter Selasky {
458d59ecb2SHans Petter Selasky 	return -socreate(family, res, type, proto, curthread->td_ucred,
468d59ecb2SHans Petter Selasky 	    curthread);
478d59ecb2SHans Petter Selasky }
488d59ecb2SHans Petter Selasky 
498d59ecb2SHans Petter Selasky static inline int
508d59ecb2SHans Petter Selasky sock_getname(struct socket *so, struct sockaddr *addr, int *sockaddr_len,
518d59ecb2SHans Petter Selasky     int peer)
528d59ecb2SHans Petter Selasky {
538d59ecb2SHans Petter Selasky 	struct sockaddr *nam;
548d59ecb2SHans Petter Selasky 	int error;
558d59ecb2SHans Petter Selasky 
568d59ecb2SHans Petter Selasky 	nam = NULL;
578d59ecb2SHans Petter Selasky 	if (peer) {
588d59ecb2SHans Petter Selasky 		if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0)
598d59ecb2SHans Petter Selasky 			return (-ENOTCONN);
608d59ecb2SHans Petter Selasky 
618d59ecb2SHans Petter Selasky 		error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, &nam);
628d59ecb2SHans Petter Selasky 	} else
638d59ecb2SHans Petter Selasky 		error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, &nam);
648d59ecb2SHans Petter Selasky 	if (error)
658d59ecb2SHans Petter Selasky 		return (-error);
668d59ecb2SHans Petter Selasky 	*addr = *nam;
678d59ecb2SHans Petter Selasky 	*sockaddr_len = addr->sa_len;
688d59ecb2SHans Petter Selasky 
698d59ecb2SHans Petter Selasky 	free(nam, M_SONAME);
708d59ecb2SHans Petter Selasky 	return (0);
718d59ecb2SHans Petter Selasky }
728d59ecb2SHans Petter Selasky 
738d59ecb2SHans Petter Selasky static inline void
748d59ecb2SHans Petter Selasky sock_release(struct socket *so)
758d59ecb2SHans Petter Selasky {
768d59ecb2SHans Petter Selasky 	soclose(so);
778d59ecb2SHans Petter Selasky }
788d59ecb2SHans Petter Selasky 
798d59ecb2SHans Petter Selasky #endif	/* _LINUX_NET_H_ */
80