Print this page
8330 Add svc_tp_create_addr to libnsl
Reviewed by: Paul Dagnelie <pcd@delphix.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sebastien Roy <sebastien.roy@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libnsl/rpc/svc_generic.c
+++ new/usr/src/lib/libnsl/rpc/svc_generic.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 + * Copyright 2016 Nexenta Systems, Inc. All rights reserved.
23 24 * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
24 - * Copyright 2014 Nexenta Systems, Inc. All rights reserved.
25 25 */
26 26
27 27 /* Copyright (c) 1988 AT&T */
28 28 /* All Rights Reserved */
29 29
30 30 /*
31 31 * svc_generic.c, Server side for RPC.
32 32 *
33 33 */
34 34
35 35 #include "mt.h"
36 36 #include <stdlib.h>
37 37 #include <sys/socket.h>
38 38 #include <netinet/in.h>
39 39 #include <netinet/tcp.h>
40 40 #include <netinet/udp.h>
41 41 #include <inttypes.h>
42 42 #include "rpc_mt.h"
43 43 #include <stdio.h>
44 44 #include <rpc/rpc.h>
45 45 #include <sys/types.h>
46 46 #include <errno.h>
47 47 #include <syslog.h>
48 48 #include <rpc/nettype.h>
49 49 #include <malloc.h>
50 50 #include <string.h>
51 51 #include <stropts.h>
52 52 #include <tsol/label.h>
53 53 #include <nfs/nfs.h>
54 54 #include <nfs/nfs_acl.h>
55 55 #include <rpcsvc/mount.h>
56 56 #include <rpcsvc/nsm_addr.h>
57 57 #include <rpcsvc/rquota.h>
58 58 #include <rpcsvc/sm_inter.h>
59 59 #include <rpcsvc/nlm_prot.h>
60 60
61 61 extern int __svc_vc_setflag(SVCXPRT *, int);
62 62
63 63 extern SVCXPRT *svc_dg_create_private(int, uint_t, uint_t);
64 64 extern SVCXPRT *svc_vc_create_private(int, uint_t, uint_t);
65 65 extern SVCXPRT *svc_fd_create_private(int, uint_t, uint_t);
66 66
67 67 extern bool_t __svc_add_to_xlist(SVCXPRT_LIST **, SVCXPRT *, mutex_t *);
68 68 extern void __svc_free_xlist(SVCXPRT_LIST **, mutex_t *);
69 69
70 70 extern bool_t __rpc_try_doors(const char *, bool_t *);
71 71
72 72 /*
73 73 * The highest level interface for server creation.
74 74 * It tries for all the nettokens in that particular class of token
75 75 * and returns the number of handles it can create and/or find.
76 76 *
77 77 * It creates a link list of all the handles it could create.
78 78 * If svc_create() is called multiple times, it uses the handle
79 79 * created earlier instead of creating a new handle every time.
↓ open down ↓ |
45 lines elided |
↑ open up ↑ |
80 80 */
81 81
82 82 /* VARIABLES PROTECTED BY xprtlist_lock: xprtlist */
83 83
84 84 SVCXPRT_LIST *_svc_xprtlist = NULL;
85 85 extern mutex_t xprtlist_lock;
86 86
87 87 static SVCXPRT * svc_tli_create_common(int, const struct netconfig *,
88 88 const struct t_bind *, uint_t, uint_t, boolean_t);
89 89
90 +static SVCXPRT *svc_tp_create_bind(void (*dispatch)(),
91 + const rpcprog_t, const rpcvers_t,
92 + const struct netconfig *, const struct t_bind *);
93 +
90 94 boolean_t
91 95 is_multilevel(rpcprog_t prognum)
92 96 {
93 97 /* This is a list of identified multilevel service provider */
94 98 if ((prognum == MOUNTPROG) || (prognum == NFS_PROGRAM) ||
95 99 (prognum == NFS_ACL_PROGRAM) || (prognum == NLM_PROG) ||
96 100 (prognum == NSM_ADDR_PROGRAM) || (prognum == RQUOTAPROG) ||
97 101 (prognum == SM_PROG))
98 102 return (B_TRUE);
99 103
100 104 return (B_FALSE);
101 105 }
102 106
103 107 void
104 108 __svc_free_xprtlist(void)
105 109 {
106 110 __svc_free_xlist(&_svc_xprtlist, &xprtlist_lock);
107 111 }
108 112
109 113 int
110 114 svc_create(void (*dispatch)(), const rpcprog_t prognum, const rpcvers_t versnum,
111 115 const char *nettype)
112 116 {
113 117 SVCXPRT_LIST *l;
114 118 int num = 0;
115 119 SVCXPRT *xprt;
116 120 struct netconfig *nconf;
117 121 void *handle;
118 122 bool_t try_others;
119 123
120 124 /*
121 125 * Check if service should register over doors transport.
122 126 */
123 127 if (__rpc_try_doors(nettype, &try_others)) {
124 128 if (svc_door_create(dispatch, prognum, versnum, 0) == NULL)
125 129 (void) syslog(LOG_ERR,
126 130 "svc_create: could not register over doors");
127 131 else
128 132 num++;
129 133 }
130 134 if (!try_others)
131 135 return (num);
132 136 if ((handle = __rpc_setconf((char *)nettype)) == NULL) {
133 137 (void) syslog(LOG_ERR, "svc_create: unknown protocol");
134 138 return (0);
135 139 }
136 140 while (nconf = __rpc_getconf(handle)) {
137 141 (void) mutex_lock(&xprtlist_lock);
138 142 for (l = _svc_xprtlist; l; l = l->next) {
139 143 if (strcmp(l->xprt->xp_netid, nconf->nc_netid) == 0) {
140 144 /* Found an old one, use it */
141 145 (void) rpcb_unset(prognum, versnum, nconf);
142 146 if (svc_reg(l->xprt, prognum, versnum,
143 147 dispatch, nconf) == FALSE)
144 148 (void) syslog(LOG_ERR, "svc_create: "
145 149 "could not register prog %d vers "
146 150 "%d on %s",
147 151 prognum, versnum, nconf->nc_netid);
148 152 else
149 153 num++;
150 154 break;
151 155 }
152 156 }
153 157 (void) mutex_unlock(&xprtlist_lock);
154 158 if (l == NULL) {
155 159 /* It was not found. Now create a new one */
156 160 xprt = svc_tp_create(dispatch, prognum, versnum, nconf);
157 161 if (xprt) {
158 162 if (!__svc_add_to_xlist(&_svc_xprtlist, xprt,
159 163 &xprtlist_lock)) {
160 164 (void) syslog(LOG_ERR,
161 165 "svc_create: no memory");
162 166 return (0);
163 167 }
164 168 num++;
165 169 }
166 170 }
167 171 }
168 172 __rpc_endconf(handle);
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
169 173 /*
170 174 * In case of num == 0; the error messages are generated by the
171 175 * underlying layers; and hence not needed here.
172 176 */
173 177 return (num);
174 178 }
175 179
176 180 /*
177 181 * The high level interface to svc_tli_create().
178 182 * It tries to create a server for "nconf" and registers the service
179 - * with the rpcbind. It calls svc_tli_create();
183 + * with the rpcbind.
180 184 */
181 185 SVCXPRT *
182 186 svc_tp_create(void (*dispatch)(), const rpcprog_t prognum,
183 - const rpcvers_t versnum, const struct netconfig *nconf)
187 + const rpcvers_t versnum, const struct netconfig *nconf)
184 188 {
189 + return (svc_tp_create_bind(dispatch, prognum, versnum, nconf, NULL));
190 +}
191 +
192 +/*
193 + * svc_tp_create_addr()
194 + * Variant of svc_tp_create() that allows specifying just the
195 + * the binding address, for convenience.
196 + */
197 +SVCXPRT *
198 +svc_tp_create_addr(void (*dispatch)(), const rpcprog_t prognum,
199 + const rpcvers_t versnum, const struct netconfig *nconf,
200 + const struct netbuf *addr)
201 +{
202 + struct t_bind bind;
203 + struct t_bind *bindp = NULL;
204 +
205 + if (addr != NULL) {
206 +
207 + bind.addr = *addr;
208 + if (!rpc_control(__RPC_SVC_LSTNBKLOG_GET, &bind.qlen)) {
209 + syslog(LOG_ERR,
210 + "svc_tp_create: can't get listen backlog");
211 + return (NULL);
212 + }
213 + bindp = &bind;
214 + }
215 +
216 + /*
217 + * When bindp == NULL, this is the same as svc_tp_create().
218 + */
219 + return (svc_tp_create_bind(dispatch, prognum, versnum,
220 + nconf, bindp));
221 +}
222 +
223 +static SVCXPRT *
224 +svc_tp_create_bind(void (*dispatch)(), const rpcprog_t prognum,
225 + const rpcvers_t versnum, const struct netconfig *nconf,
226 + const struct t_bind *bindaddr)
227 +{
185 228 SVCXPRT *xprt;
186 229 boolean_t anon_mlp = B_FALSE;
187 230
188 231 if (nconf == NULL) {
189 232 (void) syslog(LOG_ERR, "svc_tp_create: invalid netconfig "
190 233 "structure for prog %d vers %d", prognum, versnum);
191 234 return (NULL);
192 235 }
193 236
194 237 /* Some programs need to allocate MLP for multilevel services */
195 238 if (is_system_labeled() && is_multilevel(prognum))
196 239 anon_mlp = B_TRUE;
197 - xprt = svc_tli_create_common(RPC_ANYFD, nconf, NULL, 0, 0, anon_mlp);
240 + xprt = svc_tli_create_common(RPC_ANYFD, nconf, bindaddr, 0, 0,
241 + anon_mlp);
198 242 if (xprt == NULL)
199 243 return (NULL);
200 244
201 245 (void) rpcb_unset(prognum, versnum, (struct netconfig *)nconf);
202 246 if (svc_reg(xprt, prognum, versnum, dispatch, nconf) == FALSE) {
203 247 (void) syslog(LOG_ERR,
204 248 "svc_tp_create: Could not register prog %d vers %d on %s",
205 249 prognum, versnum, nconf->nc_netid);
206 250 SVC_DESTROY(xprt);
207 251 return (NULL);
208 252 }
209 253 return (xprt);
210 254 }
211 255
212 256 SVCXPRT *
213 257 svc_tli_create(const int fd, const struct netconfig *nconf,
214 258 const struct t_bind *bindaddr, const uint_t sendsz, const uint_t recvsz)
215 259 {
216 260 return (svc_tli_create_common(fd, nconf, bindaddr, sendsz, recvsz, 0));
217 261 }
218 262
219 263 /*
220 264 * If fd is RPC_ANYFD, then it opens a fd for the given transport
221 265 * provider (nconf cannot be NULL then). If the t_state is T_UNBND and
222 266 * bindaddr is NON-NULL, it performs a t_bind using the bindaddr. For
223 267 * NULL bindadr and Connection oriented transports, the value of qlen
224 268 * is set arbitrarily.
225 269 *
226 270 * If sendsz or recvsz are zero, their default values are chosen.
227 271 */
228 272 SVCXPRT *
229 273 svc_tli_create_common(const int ofd, const struct netconfig *nconf,
230 274 const struct t_bind *bindaddr, const uint_t sendsz,
231 275 const uint_t recvsz, boolean_t mlp_flag)
232 276 {
233 277 SVCXPRT *xprt = NULL; /* service handle */
234 278 struct t_info tinfo; /* transport info */
235 279 struct t_bind *tres = NULL; /* bind info */
236 280 bool_t madefd = FALSE; /* whether fd opened here */
237 281 int state; /* state of the transport provider */
238 282 int fd = ofd;
239 283
240 284 if (fd == RPC_ANYFD) {
241 285 if (nconf == NULL) {
242 286 (void) syslog(LOG_ERR,
243 287 "svc_tli_create: invalid netconfig");
244 288 return (NULL);
245 289 }
246 290 fd = t_open(nconf->nc_device, O_RDWR, &tinfo);
247 291 if (fd == -1) {
248 292 char errorstr[100];
249 293
250 294 __tli_sys_strerror(errorstr, sizeof (errorstr),
251 295 t_errno, errno);
252 296 (void) syslog(LOG_ERR, "svc_tli_create: could not open "
253 297 "connection for %s: %s", nconf->nc_netid, errorstr);
254 298 return (NULL);
255 299 }
256 300 madefd = TRUE;
257 301 state = T_UNBND;
258 302 } else {
259 303 /*
260 304 * It is an open descriptor. Sync it & get the transport info.
261 305 */
262 306 if ((state = t_sync(fd)) == -1) {
263 307 char errorstr[100];
264 308
265 309 __tli_sys_strerror(errorstr, sizeof (errorstr),
266 310 t_errno, errno);
267 311 (void) syslog(LOG_ERR,
268 312 "svc_tli_create: could not do t_sync: %s",
269 313 errorstr);
270 314 return (NULL);
271 315 }
272 316 if (t_getinfo(fd, &tinfo) == -1) {
273 317 char errorstr[100];
274 318
275 319 __tli_sys_strerror(errorstr, sizeof (errorstr),
276 320 t_errno, errno);
277 321 (void) syslog(LOG_ERR, "svc_tli_create: could not get "
278 322 "transport information: %s", errorstr);
279 323 return (NULL);
280 324 }
281 325 /* Enable options of returning the ip's for udp */
282 326 if (nconf) {
283 327 int ret = 0;
284 328 if (strcmp(nconf->nc_netid, "udp6") == 0) {
285 329 ret = __rpc_tli_set_options(fd, IPPROTO_IPV6,
286 330 IPV6_RECVPKTINFO, 1);
287 331 if (ret < 0) {
288 332 char errorstr[100];
289 333
290 334 __tli_sys_strerror(errorstr,
291 335 sizeof (errorstr), t_errno, errno);
292 336 (void) syslog(LOG_ERR,
293 337 "svc_tli_create: "
294 338 "IPV6_RECVPKTINFO(1): %s",
295 339 errorstr);
296 340 return (NULL);
297 341 }
298 342 } else if (strcmp(nconf->nc_netid, "udp") == 0) {
299 343 ret = __rpc_tli_set_options(fd, IPPROTO_IP,
300 344 IP_RECVDSTADDR, 1);
301 345 if (ret < 0) {
302 346 char errorstr[100];
303 347
304 348 __tli_sys_strerror(errorstr,
305 349 sizeof (errorstr), t_errno, errno);
306 350 (void) syslog(LOG_ERR,
307 351 "svc_tli_create: "
308 352 "IP_RECVDSTADDR(1): %s", errorstr);
309 353 return (NULL);
310 354 }
311 355 }
312 356 }
313 357 }
314 358
315 359 /*
316 360 * If the fd is unbound, try to bind it.
↓ open down ↓ |
109 lines elided |
↑ open up ↑ |
317 361 * In any case, try to get its bound info in tres
318 362 */
319 363 /* LINTED pointer alignment */
320 364 tres = (struct t_bind *)t_alloc(fd, T_BIND, T_ADDR);
321 365 if (tres == NULL) {
322 366 (void) syslog(LOG_ERR, "svc_tli_create: No memory!");
323 367 goto freedata;
324 368 }
325 369
326 370 switch (state) {
327 - bool_t tcp, exclbind;
328 371 case T_UNBND:
329 372 /* If this is a labeled system, then ask for an MLP */
330 373 if (is_system_labeled() &&
331 374 (strcmp(nconf->nc_protofmly, NC_INET) == 0 ||
332 375 strcmp(nconf->nc_protofmly, NC_INET6) == 0)) {
333 376 (void) __rpc_tli_set_options(fd, SOL_SOCKET,
334 377 SO_RECVUCRED, 1);
335 378 if (mlp_flag)
336 379 (void) __rpc_tli_set_options(fd, SOL_SOCKET,
337 380 SO_ANON_MLP, 1);
338 381 }
339 382
340 - /*
341 - * SO_EXCLBIND has the following properties
342 - * - an fd bound to port P via IPv4 will prevent an IPv6
343 - * bind to port P (and vice versa)
344 - * - an fd bound to a wildcard IP address for port P will
345 - * prevent a more specific IP address bind to port P
346 - * (see {tcp,udp}.c for details)
347 - *
348 - * We use the latter property to prevent hijacking of RPC
349 - * services that reside at non-privileged ports.
350 - */
351 - tcp = nconf ? (strcmp(nconf->nc_proto, NC_TCP) == 0) : 0;
352 - if (nconf &&
353 - (tcp || (strcmp(nconf->nc_proto, NC_UDP) == 0)) &&
354 - rpc_control(__RPC_SVC_EXCLBIND_GET, &exclbind)) {
355 - if (exclbind) {
356 - if (__rpc_tli_set_options(fd, SOL_SOCKET,
357 - SO_EXCLBIND, 1) < 0) {
358 - syslog(LOG_ERR,
359 - "svc_tli_create: can't set EXCLBIND [netid='%s']",
360 - nconf->nc_netid);
361 - goto freedata;
362 - }
363 - }
364 - }
365 383 if (bindaddr) {
384 + /*
385 + * Services that specify a bind address typically
386 + * use a fixed service (IP port) so we need to set
387 + * SO_REUSEADDR to prevent bind errors on restart.
388 + */
389 + if (bindaddr->addr.len != 0)
390 + (void) __rpc_tli_set_options(fd, SOL_SOCKET,
391 + SO_REUSEADDR, 1);
366 392 if (t_bind(fd, (struct t_bind *)bindaddr, tres) == -1) {
367 393 char errorstr[100];
368 394
369 395 __tli_sys_strerror(errorstr, sizeof (errorstr),
370 396 t_errno, errno);
371 397 (void) syslog(LOG_ERR,
372 398 "svc_tli_create: could not bind: %s",
373 399 errorstr);
374 400 goto freedata;
375 401 }
376 402 /*
377 403 * Should compare the addresses only if addr.len
378 404 * was non-zero
379 405 */
380 406 if (bindaddr->addr.len &&
381 407 (memcmp(bindaddr->addr.buf, tres->addr.buf,
382 408 (int)tres->addr.len) != 0)) {
383 409 (void) syslog(LOG_ERR, "svc_tli_create: could "
384 410 "not bind to requested address: address "
385 411 "mismatch");
386 412 goto freedata;
387 413 }
388 414 } else {
389 415 if (rpc_control(__RPC_SVC_LSTNBKLOG_GET, &tres->qlen)
390 416 == FALSE) {
391 417 syslog(LOG_ERR,
392 418 "svc_tli_create: can't get listen backlog");
393 419 goto freedata;
394 420 }
395 421 tres->addr.len = 0;
↓ open down ↓ |
20 lines elided |
↑ open up ↑ |
396 422 if (t_bind(fd, tres, tres) == -1) {
397 423 char errorstr[100];
398 424
399 425 __tli_sys_strerror(errorstr, sizeof (errorstr),
400 426 t_errno, errno);
401 427 (void) syslog(LOG_ERR,
402 428 "svc_tli_create: could not bind: %s",
403 429 errorstr);
404 430 goto freedata;
405 431 }
432 + }
433 +
434 + /*
435 + * If requested, set SO_EXCLBIND on each binding.
436 + *
437 + * SO_EXCLBIND has the following properties
438 + * - an fd bound to port P via IPv4 will prevent an IPv6
439 + * bind to port P (and vice versa)
440 + * - an fd bound to a wildcard IP address for port P will
441 + * prevent a more specific IP address bind to port P
442 + * (see {tcp,udp}.c for details)
443 + *
444 + * We use the latter property to prevent hijacking of RPC
445 + * services that reside at non-privileged ports.
446 + *
447 + * When the bind address is not specified, each bind gets a
448 + * new port number, and (for IP transports) we should set
449 + * the exclusive flag after every IP bind. That's the
450 + * strcmp nc_proto part of the expression below.
451 + *
452 + * When the bind address IS specified, we need to set the
453 + * exclusive flag only after we've bound both IPv6+IPv4,
454 + * or the IPv4 bind will fail. Setting the exclusive flag
455 + * after the "tcp" or "udp" transport bind does that.
456 + * That's the strcmp nc_netid part below.
457 + */
458 + if (nconf != NULL && ((bindaddr == NULL &&
459 + (strcmp(nconf->nc_proto, NC_TCP) == 0 ||
460 + strcmp(nconf->nc_proto, NC_UDP) == 0)) ||
461 + (strcmp(nconf->nc_netid, "tcp") == 0 ||
462 + strcmp(nconf->nc_netid, "udp") == 0))) {
463 + bool_t exclbind = FALSE;
464 + (void) rpc_control(__RPC_SVC_EXCLBIND_GET, &exclbind);
465 + if (exclbind &&
466 + __rpc_tli_set_options(fd, SOL_SOCKET,
467 + SO_EXCLBIND, 1) < 0) {
468 + syslog(LOG_ERR,
469 + "svc_tli_create: can't set EXCLBIND [netid='%s']",
470 + nconf->nc_netid);
471 + goto freedata;
472 + }
406 473 }
407 474
408 475 /* Enable options of returning the ip's for udp */
409 476 if (nconf) {
410 477 int ret = 0;
411 478 if (strcmp(nconf->nc_netid, "udp6") == 0) {
412 479 ret = __rpc_tli_set_options(fd, IPPROTO_IPV6,
413 480 IPV6_RECVPKTINFO, 1);
414 481 if (ret < 0) {
415 482 char errorstr[100];
416 483
417 484 __tli_sys_strerror(errorstr,
418 485 sizeof (errorstr), t_errno, errno);
419 486 (void) syslog(LOG_ERR,
420 487 "svc_tli_create: "
421 488 "IPV6_RECVPKTINFO(2): %s",
422 489 errorstr);
423 490 goto freedata;
424 491 }
425 492 } else if (strcmp(nconf->nc_netid, "udp") == 0) {
426 493 ret = __rpc_tli_set_options(fd, IPPROTO_IP,
427 494 IP_RECVDSTADDR, 1);
428 495 if (ret < 0) {
429 496 char errorstr[100];
430 497
431 498 __tli_sys_strerror(errorstr,
432 499 sizeof (errorstr), t_errno, errno);
433 500 (void) syslog(LOG_ERR,
434 501 "svc_tli_create: "
435 502 "IP_RECVDSTADDR(2): %s", errorstr);
436 503 goto freedata;
437 504 }
438 505 }
439 506 }
440 507 break;
441 508
442 509 case T_IDLE:
443 510 if (bindaddr) {
444 511 /* Copy the entire stuff in tres */
445 512 if (tres->addr.maxlen < bindaddr->addr.len) {
446 513 (void) syslog(LOG_ERR,
447 514 "svc_tli_create: illegal netbuf length");
448 515 goto freedata;
449 516 }
450 517 tres->addr.len = bindaddr->addr.len;
451 518 (void) memcpy(tres->addr.buf, bindaddr->addr.buf,
452 519 (int)tres->addr.len);
453 520 } else
454 521 if (t_getname(fd, &(tres->addr), LOCALNAME) == -1)
455 522 tres->addr.len = 0;
456 523 break;
457 524 case T_INREL:
458 525 (void) t_rcvrel(fd);
459 526 (void) t_sndrel(fd);
460 527 (void) syslog(LOG_ERR, "svc_tli_create: other side wants to "
461 528 "release connection");
462 529 goto freedata;
463 530
464 531 case T_INCON:
465 532 /* Do nothing here. Assume this is handled in rendezvous */
466 533 break;
467 534 case T_DATAXFER:
468 535 /*
469 536 * This takes care of the case where a fd
470 537 * is passed on which a connection has already
471 538 * been accepted.
472 539 */
473 540 if (t_getname(fd, &(tres->addr), LOCALNAME) == -1)
474 541 tres->addr.len = 0;
475 542 break;
476 543 default:
477 544 (void) syslog(LOG_ERR,
478 545 "svc_tli_create: connection in a wierd state (%d)", state);
479 546 goto freedata;
480 547 }
481 548
482 549 /*
483 550 * call transport specific function.
484 551 */
485 552 switch (tinfo.servtype) {
486 553 case T_COTS_ORD:
487 554 case T_COTS:
488 555 if (state == T_DATAXFER)
489 556 xprt = svc_fd_create_private(fd, sendsz,
490 557 recvsz);
491 558 else
492 559 xprt = svc_vc_create_private(fd, sendsz,
493 560 recvsz);
494 561 if (!nconf || !xprt)
495 562 break;
496 563 if ((tinfo.servtype == T_COTS_ORD) &&
497 564 (state != T_DATAXFER) &&
498 565 (strcmp(nconf->nc_protofmly, "inet") == 0))
499 566 (void) __svc_vc_setflag(xprt, TRUE);
500 567 break;
501 568 case T_CLTS:
502 569 xprt = svc_dg_create_private(fd, sendsz, recvsz);
503 570 break;
504 571 default:
505 572 (void) syslog(LOG_ERR,
506 573 "svc_tli_create: bad service type");
507 574 goto freedata;
508 575 }
509 576 if (xprt == NULL)
510 577 /*
511 578 * The error messages here are spitted out by the lower layers:
512 579 * svc_vc_create(), svc_fd_create() and svc_dg_create().
513 580 */
514 581 goto freedata;
515 582
516 583 /* fill in the other xprt information */
517 584
518 585 /* Assign the local bind address */
519 586 xprt->xp_ltaddr = tres->addr;
520 587 /* Fill in type of service */
521 588 xprt->xp_type = tinfo.servtype;
522 589 tres->addr.buf = NULL;
523 590 (void) t_free((char *)tres, T_BIND);
524 591 tres = NULL;
525 592
526 593 xprt->xp_rtaddr.len = 0;
527 594 xprt->xp_rtaddr.maxlen = __rpc_get_a_size(tinfo.addr);
528 595
529 596 /* Allocate space for the remote bind info */
530 597 if ((xprt->xp_rtaddr.buf = malloc(xprt->xp_rtaddr.maxlen)) == NULL) {
531 598 (void) syslog(LOG_ERR, "svc_tli_create: No memory!");
532 599 goto freedata;
533 600 }
534 601
535 602 if (nconf) {
536 603 xprt->xp_netid = strdup(nconf->nc_netid);
537 604 if (xprt->xp_netid == NULL) {
538 605 if (xprt->xp_rtaddr.buf)
539 606 free(xprt->xp_rtaddr.buf);
540 607 syslog(LOG_ERR, "svc_tli_create: strdup failed!");
541 608 goto freedata;
542 609 }
543 610 xprt->xp_tp = strdup(nconf->nc_device);
544 611 if (xprt->xp_tp == NULL) {
545 612 if (xprt->xp_rtaddr.buf)
546 613 free(xprt->xp_rtaddr.buf);
547 614 if (xprt->xp_netid)
548 615 free(xprt->xp_netid);
549 616 syslog(LOG_ERR, "svc_tli_create: strdup failed!");
550 617 goto freedata;
551 618 }
552 619 }
553 620
554 621 /*
555 622 * if (madefd && (tinfo.servtype == T_CLTS))
556 623 * (void) ioctl(fd, I_POP, NULL);
557 624 */
558 625 xprt_register(xprt);
559 626 return (xprt);
560 627
561 628 freedata:
562 629 if (madefd)
563 630 (void) t_close(fd);
564 631 if (tres)
565 632 (void) t_free((char *)tres, T_BIND);
566 633 if (xprt) {
567 634 if (!madefd) /* so that svc_destroy doesnt close fd */
568 635 xprt->xp_fd = RPC_ANYFD;
569 636 SVC_DESTROY(xprt);
570 637 }
571 638 return (NULL);
572 639 }
↓ open down ↓ |
157 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX