xref: /freebsd/sys/rpc/getnetconfig.c (revision 1db64f89363c97858961c4df0b7d02f3223723cf)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2008 Isilon Inc http://www.isilon.com/
5  * Authors: Doug Rabson <dfr@rabson.org>
6  * Developed with Red Inc: Alfred Perlstein <alfred@freebsd.org>
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #include "opt_inet6.h"
31 
32 #include <sys/param.h>
33 #include <sys/malloc.h>
34 #include <sys/systm.h>
35 
36 #include <rpc/types.h>
37 
38 /*
39  * For in-kernel use, we use a simple compiled-in configuration.
40  */
41 
42 static struct netconfig netconfigs[] = {
43 #ifdef INET6
44 	{
45 		.nc_netid =	"udp6",
46 		.nc_semantics =	NC_TPI_CLTS,
47 		.nc_flag =	NC_VISIBLE,
48 		.nc_protofmly =	"inet6",
49 		.nc_proto =	"udp",
50 	},
51 	{
52 		.nc_netid =	"tcp6",
53 		.nc_semantics =	NC_TPI_COTS_ORD,
54 		.nc_flag =	NC_VISIBLE,
55 		.nc_protofmly =	"inet6",
56 		.nc_proto =	"tcp",
57 	},
58 #endif
59 	{
60 		.nc_netid =	"udp",
61 		.nc_semantics =	NC_TPI_CLTS,
62 		.nc_flag =	NC_VISIBLE,
63 		.nc_protofmly =	"inet",
64 		.nc_proto =	"udp",
65 	},
66 	{
67 		.nc_netid =	"tcp",
68 		.nc_semantics =	NC_TPI_COTS_ORD,
69 		.nc_flag =	NC_VISIBLE,
70 		.nc_protofmly =	"inet",
71 		.nc_proto =	"tcp",
72 	},
73 	{
74 		.nc_netid =	"local",
75 		.nc_semantics =	NC_TPI_COTS_ORD,
76 		.nc_flag =	0,
77 		.nc_protofmly =	"loopback",
78 		.nc_proto =	"",
79 	},
80 	{
81 		.nc_netid =	NULL,
82 	}
83 };
84 
85 void *
86 setnetconfig(void)
87 {
88 	struct netconfig **nconfp;
89 
90 	nconfp = malloc(sizeof(struct netconfig *), M_RPC, M_WAITOK);
91 	*nconfp = netconfigs;
92 
93 	return ((void *) nconfp);
94 }
95 
96 struct netconfig *
97 getnetconfig(void *handle)
98 {
99 	struct netconfig **nconfp = (struct netconfig **) handle;
100 	struct netconfig *nconf;
101 
102 	nconf = *nconfp;
103 	if (nconf->nc_netid == NULL)
104 		return (NULL);
105 
106 	(*nconfp)++;
107 
108 	return (nconf);
109 }
110 
111 struct netconfig *
112 getnetconfigent(const char *netid)
113 {
114 	struct netconfig *nconf;
115 
116 	for (nconf = netconfigs; nconf->nc_netid; nconf++) {
117 		if (!strcmp(netid, nconf->nc_netid))
118 			return (nconf);
119 	}
120 
121 	return (NULL);
122 }
123 
124 void
125 freenetconfigent(struct netconfig *nconf)
126 {
127 
128 }
129 
130 int
131 endnetconfig(void * handle)
132 {
133 	struct netconfig **nconfp = (struct netconfig **) handle;
134 
135 	free(nconfp, M_RPC);
136 	return (0);
137 }
138