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