author | James Kremer <James.Kremer@Sun.COM> |
Mon, 07 Jun 2010 20:28:15 -0600 | |
changeset 12581 | 18307efc4636 |
parent 12307 | eed67f0e6b33 |
child 13105 | 48f2dbca79a2 |
permissions | -rw-r--r-- |
1193 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1570 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
1193 | 7 |
* |
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
||
22 |
/* |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
23 |
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
1193 | 24 |
*/ |
25 |
||
26 |
#include <sys/types.h> |
|
27 |
#include <sys/socket.h> |
|
28 |
#include <sys/sysmacros.h> |
|
29 |
#include <sys/fm/protocol.h> |
|
30 |
||
31 |
#include <netinet/in.h> |
|
32 |
#include <arpa/inet.h> |
|
33 |
||
34 |
#include <strings.h> |
|
35 |
#include <unistd.h> |
|
36 |
#include <pthread.h> |
|
37 |
#include <alloca.h> |
|
38 |
#include <fcntl.h> |
|
39 |
#include <errno.h> |
|
40 |
#include <netdb.h> |
|
41 |
#include <poll.h> |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
42 |
#include <stdarg.h> |
1193 | 43 |
|
44 |
#include <fm/fmd_api.h> |
|
45 |
||
46 |
#define IP_MAGIC "\177FMA" /* magic string identifying a packet header */ |
|
47 |
#define IP_MAGLEN 4 /* length of magic string */ |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
48 |
#define IP_DEBUG_OFF 0 /* No informational debugging printed */ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
49 |
#define IP_DEBUG_FINE 1 /* Basic debug information printed (default) */ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
50 |
#define IP_DEBUG_FINER 2 /* More debug information printed. */ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
51 |
#define IP_DEBUG_FINEST 3 /* All debug information printed */ |
1193 | 52 |
|
53 |
typedef struct ip_hdr { |
|
54 |
char iph_magic[IP_MAGLEN]; /* magic string */ |
|
55 |
uint32_t iph_size; /* packed size */ |
|
56 |
} ip_hdr_t; |
|
57 |
||
58 |
typedef struct ip_buf { |
|
59 |
void *ipb_buf; /* data buffer */ |
|
60 |
size_t ipb_size; /* size of buffer */ |
|
61 |
} ip_buf_t; |
|
62 |
||
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
63 |
typedef struct ip_cinfo { /* Connection specific information */ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
64 |
struct addrinfo *ipc_addr; /* Connection address(es) */ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
65 |
char *ipc_name; /* The name of the server or interface */ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
66 |
int ipc_retry; /* The number of connection retries */ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
67 |
boolean_t ipc_accept; /* Will connection accept clients */ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
68 |
id_t ipc_timer; /* FMD timer id for connection */ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
69 |
struct ip_cinfo *ipc_next; /* Next conneciton in list */ |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
70 |
} ip_cinfo_t; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
71 |
|
1193 | 72 |
typedef struct ip_xprt { |
73 |
fmd_xprt_t *ipx_xprt; /* transport handle */ |
|
74 |
int ipx_flags; /* transport flags */ |
|
75 |
int ipx_fd; /* socket file descriptor */ |
|
76 |
int ipx_done; /* flag indicating connection closed */ |
|
77 |
pthread_t ipx_tid; /* recv-side auxiliary thread */ |
|
78 |
ip_buf_t ipx_sndbuf; /* buffer for sending events */ |
|
79 |
ip_buf_t ipx_rcvbuf; /* buffer for receiving events */ |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
80 |
ip_cinfo_t *ipx_cinfo; /* info for reconnect */ |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
81 |
id_t ipx_spnd_timer; /* connection suspend timer */ |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
82 |
char *ipx_addr; /* address:port of remote connection */ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
83 |
struct ip_xprt *ipx_next; /* next ip_xprt in global list */ |
1193 | 84 |
} ip_xprt_t; |
85 |
||
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
86 |
#define IPX_ID(a) ((a)->ipx_addr == NULL ? "(Not connected)" : (a)->ipx_addr) |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
87 |
|
1193 | 88 |
typedef struct ip_stat { |
89 |
fmd_stat_t ips_accfail; /* failed accepts */ |
|
90 |
fmd_stat_t ips_badmagic; /* invalid packet headers */ |
|
91 |
fmd_stat_t ips_packfail; /* failed packs */ |
|
92 |
fmd_stat_t ips_unpackfail; /* failed unpacks */ |
|
93 |
} ip_stat_t; |
|
94 |
||
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
95 |
static void ip_xprt_create(fmd_xprt_t *, int, int, ip_cinfo_t *, char *); |
1193 | 96 |
static void ip_xprt_destroy(ip_xprt_t *); |
97 |
||
98 |
static ip_stat_t ip_stat = { |
|
99 |
{ "accfail", FMD_TYPE_UINT64, "failed accepts" }, |
|
100 |
{ "badmagic", FMD_TYPE_UINT64, "invalid packet headers" }, |
|
101 |
{ "packfail", FMD_TYPE_UINT64, "failed packs" }, |
|
102 |
{ "unpackfail", FMD_TYPE_UINT64, "failed unpacks" }, |
|
103 |
}; |
|
104 |
||
105 |
static fmd_hdl_t *ip_hdl; /* module handle */ |
|
106 |
static pthread_mutex_t ip_lock; /* lock for ip_xps list */ |
|
107 |
static ip_xprt_t *ip_xps; /* list of active transports */ |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
108 |
static pthread_mutex_t ip_conns_lock; /* lock for ip_conns list */ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
109 |
static ip_cinfo_t *ip_conns; /* list of all configured connection info */ |
1193 | 110 |
static nvlist_t *ip_auth; /* authority to use for transport(s) */ |
111 |
static size_t ip_size; /* default buffer size */ |
|
112 |
static volatile int ip_quit; /* signal to quit */ |
|
113 |
static int ip_qlen; /* queue length for listen(3SOCKET) */ |
|
114 |
static int ip_mtbf; /* mtbf for simulating packet drop */ |
|
9120
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
115 |
static int ip_external; /* set transport to be "external" */ |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
116 |
static int ip_no_remote_repair; /* disallow remote repair */ |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
117 |
static int ip_hconly; /* only cache faults that are hc-scheme */ |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
118 |
static int ip_rdonly; /* force transport to be rdonly */ |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
119 |
static int ip_hc_present_only; /* only cache faults if hc-scheme and present */ |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
120 |
static char *ip_domain_name; /* set domain name for received list.suspects */ |
1193 | 121 |
static hrtime_t ip_burp; /* make mtbf slower by adding this much delay */ |
122 |
static int ip_translate; /* call fmd_xprt_translate() before sending */ |
|
123 |
static char *ip_port; /* port to connect to (or bind to if server) */ |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
124 |
static int ip_retry; /* retry count for ip_xprt_setup() -1=forever */ |
1193 | 125 |
static hrtime_t ip_sleep; /* sleep delay for ip_xprt_setup() */ |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
126 |
static int ip_debug_level; /* level for printing debug messages */ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
127 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
128 |
/* |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
129 |
* Prints a debug message to the fmd debug framework if the debug level is set |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
130 |
* to at least the given level. |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
131 |
*/ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
132 |
static void |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
133 |
ip_debug(int level, char *fmt, ...) |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
134 |
{ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
135 |
if (ip_debug_level >= level) { |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
136 |
va_list args; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
137 |
va_start(args, fmt); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
138 |
fmd_hdl_vdebug(ip_hdl, fmt, args); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
139 |
va_end(args); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
140 |
} |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
141 |
} |
1193 | 142 |
|
143 |
/* |
|
144 |
* Allocate space in ipx_sndbuf for a header and a packed XDR encoding of |
|
145 |
* the specified nvlist, and then send the buffer to our remote peer. |
|
146 |
*/ |
|
147 |
static int |
|
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
148 |
ip_fmdo_send(fmd_hdl_t *hdl, fmd_xprt_t *xp, fmd_event_t *ep, nvlist_t *nvl) |
1193 | 149 |
{ |
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
150 |
ip_xprt_t *ipx; |
1193 | 151 |
size_t size, nvsize; |
152 |
char *buf, *nvbuf; |
|
153 |
ip_hdr_t *iph; |
|
154 |
ssize_t r, n; |
|
155 |
int err; |
|
156 |
||
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
157 |
if (xp == NULL) { |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
158 |
ip_debug(IP_DEBUG_FINE, "ip_fmdo_send failed: xp=NULL\n"); |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
159 |
return (FMD_SEND_FAILED); |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
160 |
} |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
161 |
ipx = fmd_xprt_getspecific(hdl, xp); |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
162 |
|
1193 | 163 |
/* |
164 |
* For testing purposes, if ip_mtbf is non-zero, use this to pseudo- |
|
165 |
* randomly simulate the need for retries. If ip_burp is also set, |
|
166 |
* then we also suspend the transport for a bit and wake it up again. |
|
167 |
*/ |
|
168 |
if (ip_mtbf != 0 && gethrtime() % ip_mtbf == 0) { |
|
169 |
if (ip_burp != 0) { |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
170 |
ip_debug(IP_DEBUG_FINE, "burping ipx %s", IPX_ID(ipx)); |
1193 | 171 |
ipx->ipx_flags |= FMD_XPRT_SUSPENDED; |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
172 |
ipx->ipx_spnd_timer = fmd_timer_install( |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
173 |
ip_hdl, ipx, NULL, ip_burp); |
1193 | 174 |
fmd_xprt_suspend(ip_hdl, xp); |
175 |
} |
|
176 |
return (FMD_SEND_RETRY); |
|
177 |
} |
|
178 |
||
179 |
if (ip_translate && (nvl = fmd_xprt_translate(hdl, xp, ep)) == NULL) { |
|
180 |
fmd_hdl_error(hdl, "failed to translate event %p", (void *)ep); |
|
181 |
return (FMD_SEND_FAILED); |
|
182 |
} |
|
183 |
||
184 |
(void) nvlist_size(nvl, &nvsize, NV_ENCODE_XDR); |
|
185 |
size = r = sizeof (ip_hdr_t) + nvsize; |
|
186 |
||
187 |
if (ipx->ipx_sndbuf.ipb_size < size) { |
|
188 |
fmd_hdl_free(hdl, ipx->ipx_sndbuf.ipb_buf, |
|
189 |
ipx->ipx_sndbuf.ipb_size); |
|
190 |
ipx->ipx_sndbuf.ipb_size = P2ROUNDUP(size, 16); |
|
191 |
ipx->ipx_sndbuf.ipb_buf = fmd_hdl_alloc(hdl, |
|
192 |
ipx->ipx_sndbuf.ipb_size, FMD_SLEEP); |
|
193 |
} |
|
194 |
||
195 |
buf = ipx->ipx_sndbuf.ipb_buf; |
|
196 |
iph = (ip_hdr_t *)(uintptr_t)buf; |
|
197 |
nvbuf = buf + sizeof (ip_hdr_t); |
|
198 |
||
199 |
bcopy(IP_MAGIC, iph->iph_magic, IP_MAGLEN); |
|
200 |
iph->iph_size = htonl(nvsize); |
|
201 |
err = nvlist_pack(nvl, &nvbuf, &nvsize, NV_ENCODE_XDR, 0); |
|
202 |
||
203 |
if (ip_translate) |
|
204 |
nvlist_free(nvl); |
|
205 |
||
206 |
if (err != 0) { |
|
207 |
fmd_hdl_error(ip_hdl, "failed to pack event for " |
|
208 |
"transport %p: %s\n", (void *)ipx->ipx_xprt, strerror(err)); |
|
209 |
ip_stat.ips_packfail.fmds_value.ui64++; |
|
210 |
return (FMD_SEND_FAILED); |
|
211 |
} |
|
212 |
||
213 |
while (!ip_quit && r != 0) { |
|
214 |
if ((n = send(ipx->ipx_fd, buf, r, 0)) < 0) { |
|
215 |
if (errno != EINTR && errno != EWOULDBLOCK) { |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
216 |
ip_debug(IP_DEBUG_FINE, |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
217 |
"failed to send to %s", IPX_ID(ipx)); |
1193 | 218 |
return (FMD_SEND_FAILED); |
219 |
} |
|
220 |
continue; |
|
221 |
} |
|
222 |
buf += n; |
|
223 |
r -= n; |
|
224 |
} |
|
225 |
||
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
226 |
ip_debug(IP_DEBUG_FINEST, "Sent event %d bytes to %s", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
227 |
size, IPX_ID(ipx)); |
1193 | 228 |
return (FMD_SEND_SUCCESS); |
229 |
} |
|
230 |
||
231 |
/* |
|
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
232 |
* Sends events over transports that are configured read only. When the module |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
233 |
* is in read only mode it will receive all events and only send events that |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
234 |
* have a subscription set. |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
235 |
* |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
236 |
* The configuration file will have to set prop ip_rdonly true and also |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
237 |
* subscribe for events that are desired to be sent over the transport in order |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
238 |
* for this function to be used. |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
239 |
*/ |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
240 |
/* ARGSUSED */ |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
241 |
static void |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
242 |
ip_fmdo_recv(fmd_hdl_t *hdl, fmd_event_t *ep, nvlist_t *nvl, const char *class) |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
243 |
{ |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
244 |
int err; |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
245 |
ip_xprt_t *ipx; |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
246 |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
247 |
if (ip_rdonly && !ip_quit) { |
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
248 |
(void) pthread_mutex_lock(&ip_lock); |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
249 |
|
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
250 |
for (ipx = ip_xps; ipx != NULL; ipx = ipx->ipx_next) { |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
251 |
err = ip_fmdo_send(hdl, ipx->ipx_xprt, ep, nvl); |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
252 |
while (FMD_SEND_RETRY == err) { |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
253 |
err = ip_fmdo_send(hdl, ipx->ipx_xprt, ep, nvl); |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
254 |
} |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
255 |
} |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
256 |
(void) pthread_mutex_unlock(&ip_lock); |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
257 |
} |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
258 |
} |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
259 |
|
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
260 |
/* |
1193 | 261 |
* Receive a chunk of data of the specified size from our remote peer. The |
262 |
* data is received into ipx_rcvbuf, and then a pointer to the buffer is |
|
263 |
* returned. NOTE: The data is only valid until the next call to ip_xprt_recv. |
|
264 |
* If the connection breaks or ip_quit is set during receive, NULL is returned. |
|
265 |
*/ |
|
266 |
static void * |
|
267 |
ip_xprt_recv(ip_xprt_t *ipx, size_t size) |
|
268 |
{ |
|
269 |
char *buf = ipx->ipx_rcvbuf.ipb_buf; |
|
270 |
ssize_t n, r = size; |
|
271 |
||
272 |
if (ipx->ipx_rcvbuf.ipb_size < size) { |
|
273 |
fmd_hdl_free(ip_hdl, ipx->ipx_rcvbuf.ipb_buf, |
|
274 |
ipx->ipx_rcvbuf.ipb_size); |
|
275 |
ipx->ipx_rcvbuf.ipb_size = P2ROUNDUP(size, 16); |
|
276 |
ipx->ipx_rcvbuf.ipb_buf = buf = fmd_hdl_alloc(ip_hdl, |
|
277 |
ipx->ipx_rcvbuf.ipb_size, FMD_SLEEP); |
|
278 |
} |
|
279 |
||
280 |
while (!ip_quit && r != 0) { |
|
281 |
if ((n = recv(ipx->ipx_fd, buf, r, MSG_WAITALL)) == 0) { |
|
282 |
ipx->ipx_done++; |
|
283 |
return (NULL); |
|
284 |
} |
|
285 |
||
286 |
if (n < 0) { |
|
287 |
if (errno != EINTR && errno != EWOULDBLOCK) { |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
288 |
ip_debug(IP_DEBUG_FINE, |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
289 |
"failed to recv on ipx %s", IPX_ID(ipx)); |
1193 | 290 |
} |
291 |
continue; |
|
292 |
} |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
293 |
/* Reset retry counter after a successful connection */ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
294 |
if (ipx->ipx_cinfo) { |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
295 |
ipx->ipx_cinfo->ipc_retry = ip_retry; |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
296 |
} |
1193 | 297 |
|
298 |
buf += n; |
|
299 |
r -= n; |
|
300 |
} |
|
301 |
||
302 |
return (r ? NULL: ipx->ipx_rcvbuf.ipb_buf); |
|
303 |
} |
|
304 |
||
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
305 |
/* |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
306 |
* Sets the address/port of the remote connection in the connection info struct |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
307 |
* This is called after a TCP session has been set up with a known remote |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
308 |
* address (sap) |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
309 |
*/ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
310 |
static void |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
311 |
ip_xprt_set_addr(ip_xprt_t *ipx, const struct sockaddr *sap) |
1193 | 312 |
{ |
313 |
const struct sockaddr_in6 *sin6 = (const void *)sap; |
|
314 |
const struct sockaddr_in *sin = (const void *)sap; |
|
315 |
||
316 |
char buf[INET6_ADDRSTRLEN + 16]; |
|
317 |
struct in_addr v4addr; |
|
318 |
in_port_t port; |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
319 |
int n; |
1193 | 320 |
|
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
321 |
ip_debug(IP_DEBUG_FINER, "Enter ip_xprt_set_addr"); |
1193 | 322 |
|
323 |
if (sap->sa_family == AF_INET6 && |
|
324 |
IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) { |
|
325 |
IN6_V4MAPPED_TO_INADDR(&sin6->sin6_addr, &v4addr); |
|
326 |
(void) inet_ntop(AF_INET, &v4addr, buf, sizeof (buf)); |
|
327 |
port = ntohs(sin6->sin6_port); |
|
328 |
} else if (sap->sa_family == AF_INET6) { |
|
329 |
(void) inet_ntop(AF_INET6, &sin6->sin6_addr, buf, sizeof (buf)); |
|
330 |
port = ntohs(sin6->sin6_port); |
|
331 |
} else { |
|
332 |
(void) inet_ntop(AF_INET, &sin->sin_addr, buf, sizeof (buf)); |
|
333 |
port = ntohs(sin->sin_port); |
|
334 |
} |
|
335 |
||
336 |
n = strlen(buf); |
|
337 |
(void) snprintf(buf + n, sizeof (buf) - n, ":%u", port); |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
338 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
339 |
if (ipx->ipx_addr) |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
340 |
fmd_hdl_strfree(ip_hdl, ipx->ipx_addr); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
341 |
ipx->ipx_addr = fmd_hdl_strdup(ip_hdl, buf, FMD_SLEEP); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
342 |
ip_debug(IP_DEBUG_FINE, "connection addr is %s on %p", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
343 |
ipx->ipx_addr, (void *)ipx); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
344 |
} |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
345 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
346 |
static nvlist_t * |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
347 |
ip_xprt_auth(ip_xprt_t *ipx) |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
348 |
{ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
349 |
nvlist_t *nvl; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
350 |
int err; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
351 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
352 |
ip_debug(IP_DEBUG_FINER, "Enter ip_xprt_auth"); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
353 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
354 |
if (ip_auth != NULL) |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
355 |
err = nvlist_dup(ip_auth, &nvl, 0); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
356 |
else |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
357 |
err = nvlist_alloc(&nvl, 0, 0); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
358 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
359 |
if (err != 0) { |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
360 |
fmd_hdl_abort(ip_hdl, "failed to create nvlist for " |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
361 |
"authority: %s\n", strerror(err)); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
362 |
} |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
363 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
364 |
if (ip_auth != NULL) |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
365 |
return (nvl); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
366 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
367 |
ip_debug(IP_DEBUG_FINE, "ip_authority %s=%s\n", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
368 |
FM_FMRI_AUTH_SERVER, ipx->ipx_addr); |
1193 | 369 |
|
370 |
(void) nvlist_add_uint8(nvl, FM_VERSION, FM_FMRI_AUTH_VERSION); |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
371 |
(void) nvlist_add_string(nvl, FM_FMRI_AUTH_SERVER, ipx->ipx_addr); |
1193 | 372 |
|
373 |
return (nvl); |
|
374 |
} |
|
375 |
||
376 |
static void |
|
377 |
ip_xprt_accept(ip_xprt_t *ipx) |
|
378 |
{ |
|
1570 | 379 |
struct sockaddr_storage sa; |
1193 | 380 |
socklen_t salen = sizeof (sa); |
381 |
fmd_xprt_t *xp; |
|
382 |
int fd; |
|
383 |
||
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
384 |
ip_debug(IP_DEBUG_FINER, "Enter ip_xprt_accept"); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
385 |
|
1570 | 386 |
if ((fd = accept(ipx->ipx_fd, (struct sockaddr *)&sa, &salen)) == -1) { |
1193 | 387 |
fmd_hdl_error(ip_hdl, "failed to accept connection"); |
388 |
ip_stat.ips_accfail.fmds_value.ui64++; |
|
389 |
return; |
|
390 |
} |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
391 |
ip_debug(IP_DEBUG_FINE, "Accepted socket on fd %d", fd); |
1193 | 392 |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
393 |
ip_xprt_set_addr(ipx, (struct sockaddr *)&sa); |
1570 | 394 |
xp = fmd_xprt_open(ip_hdl, ipx->ipx_flags, |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
395 |
ip_xprt_auth(ipx), NULL); |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
396 |
ip_xprt_create(xp, fd, ipx->ipx_flags, ipx->ipx_cinfo, ipx->ipx_addr); |
1193 | 397 |
} |
398 |
||
399 |
static void |
|
400 |
ip_xprt_recv_event(ip_xprt_t *ipx) |
|
401 |
{ |
|
402 |
ip_hdr_t *iph; |
|
403 |
nvlist_t *nvl; |
|
404 |
size_t size; |
|
405 |
void *buf; |
|
406 |
int err; |
|
407 |
||
408 |
if ((iph = ip_xprt_recv(ipx, sizeof (ip_hdr_t))) == NULL) |
|
409 |
return; /* connection broken */ |
|
410 |
||
411 |
if (bcmp(iph->iph_magic, IP_MAGIC, IP_MAGLEN) != 0) { |
|
412 |
fmd_hdl_error(ip_hdl, |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
413 |
"invalid hdr magic %x.%x.%x.%x from transport %s\n", |
1193 | 414 |
iph->iph_magic[0], iph->iph_magic[1], iph->iph_magic[2], |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
415 |
iph->iph_magic[3], IPX_ID(ipx)); |
1193 | 416 |
ip_stat.ips_badmagic.fmds_value.ui64++; |
417 |
return; |
|
418 |
} |
|
419 |
||
420 |
size = ntohl(iph->iph_size); |
|
421 |
||
422 |
if ((buf = ip_xprt_recv(ipx, size)) == NULL) |
|
423 |
return; /* connection broken */ |
|
424 |
||
425 |
if ((err = nvlist_unpack(buf, size, &nvl, 0)) != 0) { |
|
426 |
fmd_hdl_error(ip_hdl, "failed to unpack event from " |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
427 |
"transport %s: %s\n", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
428 |
IPX_ID(ipx), strerror(err)); |
1193 | 429 |
ip_stat.ips_unpackfail.fmds_value.ui64++; |
9120
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
430 |
} else { |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
431 |
if (ip_domain_name) |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
432 |
fmd_xprt_add_domain(ip_hdl, nvl, ip_domain_name); |
1193 | 433 |
fmd_xprt_post(ip_hdl, ipx->ipx_xprt, nvl, 0); |
9120
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
434 |
} |
1193 | 435 |
|
436 |
if (fmd_xprt_error(ip_hdl, ipx->ipx_xprt)) { |
|
437 |
fmd_hdl_error(ip_hdl, "protocol error on transport %p", |
|
438 |
(void *)ipx->ipx_xprt); |
|
439 |
ipx->ipx_done++; |
|
440 |
} |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
441 |
ip_debug(IP_DEBUG_FINEST, "Recv event %d bytes from %s", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
442 |
size, IPX_ID(ipx)); |
1193 | 443 |
} |
444 |
||
445 |
static void |
|
446 |
ip_xprt_thread(void *arg) |
|
447 |
{ |
|
448 |
ip_xprt_t *ipx = arg; |
|
1570 | 449 |
struct sockaddr_storage sa; |
1193 | 450 |
socklen_t salen = sizeof (sa); |
451 |
struct pollfd pfd; |
|
452 |
||
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
453 |
ip_debug(IP_DEBUG_FINER, "Enter ip_xprt_thread"); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
454 |
|
1193 | 455 |
while (!ip_quit && !ipx->ipx_done) { |
456 |
if (ipx->ipx_xprt != NULL || (ipx->ipx_flags & FMD_XPRT_ACCEPT)) |
|
457 |
pfd.events = POLLIN; |
|
458 |
else |
|
459 |
pfd.events = POLLOUT; |
|
460 |
||
461 |
pfd.fd = ipx->ipx_fd; |
|
462 |
pfd.revents = 0; |
|
463 |
||
464 |
if (poll(&pfd, 1, -1) <= 0) |
|
465 |
continue; /* loop around and check ip_quit */ |
|
466 |
||
467 |
if (pfd.revents & (POLLHUP | POLLERR)) { |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
468 |
ip_debug(IP_DEBUG_FINE, "hangup fd %d\n", ipx->ipx_fd); |
1193 | 469 |
break; |
470 |
} |
|
471 |
||
472 |
if (pfd.revents & POLLOUT) { |
|
473 |
/* |
|
474 |
* Once we're connected, there's no reason to have our |
|
475 |
* calls to recv() and send() be non-blocking since we |
|
476 |
* we have separate threads for each: clear O_NONBLOCK. |
|
477 |
*/ |
|
478 |
(void) fcntl(ipx->ipx_fd, F_SETFL, |
|
479 |
fcntl(ipx->ipx_fd, F_GETFL, 0) & ~O_NONBLOCK); |
|
480 |
||
1570 | 481 |
if (getpeername(ipx->ipx_fd, (struct sockaddr *)&sa, |
482 |
&salen) != 0) { |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
483 |
ip_debug(IP_DEBUG_FINE, |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
484 |
"Not connected, no remote name for fd %d. " |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
485 |
" Will retry.", |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
486 |
ipx->ipx_fd); |
1193 | 487 |
bzero(&sa, sizeof (sa)); |
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
488 |
break; |
1193 | 489 |
} |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
490 |
ip_xprt_set_addr(ipx, (struct sockaddr *)&sa); |
1570 | 491 |
ipx->ipx_xprt = fmd_xprt_open(ip_hdl, ipx->ipx_flags, |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
492 |
ip_xprt_auth(ipx), ipx); |
1193 | 493 |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
494 |
ip_debug(IP_DEBUG_FINE, "connect fd %d ipx %p", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
495 |
ipx->ipx_fd, (void *)ipx); |
1193 | 496 |
continue; |
497 |
} |
|
498 |
||
499 |
if (pfd.revents & POLLIN) { |
|
500 |
if (ipx->ipx_xprt == NULL) |
|
501 |
ip_xprt_accept(ipx); |
|
502 |
else |
|
503 |
ip_xprt_recv_event(ipx); |
|
504 |
} |
|
505 |
} |
|
506 |
||
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
507 |
ipx->ipx_cinfo->ipc_timer = fmd_timer_install(ip_hdl, ipx, NULL, 0); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
508 |
ip_debug(IP_DEBUG_FINE, "close fd %d (timer %d)", ipx->ipx_fd, |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
509 |
(int)ipx->ipx_cinfo->ipc_timer); |
1193 | 510 |
} |
511 |
||
512 |
static void |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
513 |
ip_xprt_create(fmd_xprt_t *xp, int fd, int flags, ip_cinfo_t *cinfo, char *addr) |
1193 | 514 |
{ |
515 |
ip_xprt_t *ipx = fmd_hdl_zalloc(ip_hdl, sizeof (ip_xprt_t), FMD_SLEEP); |
|
516 |
||
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
517 |
ip_debug(IP_DEBUG_FINER, "Enter ip_xprt_create %p", (void *)ipx); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
518 |
|
1193 | 519 |
ipx->ipx_xprt = xp; |
520 |
ipx->ipx_flags = flags; |
|
521 |
ipx->ipx_fd = fd; |
|
522 |
ipx->ipx_tid = fmd_thr_create(ip_hdl, ip_xprt_thread, ipx); |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
523 |
ipx->ipx_cinfo = cinfo; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
524 |
ipx->ipx_addr = fmd_hdl_strdup(ip_hdl, addr, FMD_SLEEP); |
1193 | 525 |
|
526 |
if (ipx->ipx_xprt != NULL) |
|
527 |
fmd_xprt_setspecific(ip_hdl, ipx->ipx_xprt, ipx); |
|
528 |
||
529 |
(void) pthread_mutex_lock(&ip_lock); |
|
530 |
||
531 |
ipx->ipx_next = ip_xps; |
|
532 |
ip_xps = ipx; |
|
533 |
||
534 |
(void) pthread_mutex_unlock(&ip_lock); |
|
535 |
} |
|
536 |
||
537 |
static void |
|
538 |
ip_xprt_destroy(ip_xprt_t *ipx) |
|
539 |
{ |
|
540 |
ip_xprt_t *ipp, **ppx = &ip_xps; |
|
541 |
||
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
542 |
ip_debug(IP_DEBUG_FINER, "Enter ip_xprt_destory %s %p", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
543 |
IPX_ID(ipx), (void *)ipx); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
544 |
|
1193 | 545 |
(void) pthread_mutex_lock(&ip_lock); |
546 |
||
547 |
for (ipp = *ppx; ipp != NULL; ipp = ipp->ipx_next) { |
|
548 |
if (ipp != ipx) |
|
549 |
ppx = &ipp->ipx_next; |
|
550 |
else |
|
551 |
break; |
|
552 |
} |
|
553 |
||
554 |
if (ipp != ipx) { |
|
555 |
(void) pthread_mutex_unlock(&ip_lock); |
|
556 |
fmd_hdl_abort(ip_hdl, "ipx %p not on xps list\n", (void *)ipx); |
|
557 |
} |
|
558 |
||
559 |
*ppx = ipx->ipx_next; |
|
560 |
ipx->ipx_next = NULL; |
|
561 |
||
562 |
(void) pthread_mutex_unlock(&ip_lock); |
|
563 |
||
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
564 |
if (ipx->ipx_spnd_timer) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
565 |
fmd_timer_remove(ip_hdl, ipx->ipx_spnd_timer); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
566 |
|
1193 | 567 |
fmd_thr_signal(ip_hdl, ipx->ipx_tid); |
568 |
fmd_thr_destroy(ip_hdl, ipx->ipx_tid); |
|
569 |
||
570 |
if (ipx->ipx_xprt != NULL) |
|
571 |
fmd_xprt_close(ip_hdl, ipx->ipx_xprt); |
|
572 |
||
573 |
fmd_hdl_free(ip_hdl, ipx->ipx_sndbuf.ipb_buf, ipx->ipx_sndbuf.ipb_size); |
|
574 |
fmd_hdl_free(ip_hdl, ipx->ipx_rcvbuf.ipb_buf, ipx->ipx_rcvbuf.ipb_size); |
|
575 |
||
576 |
(void) close(ipx->ipx_fd); |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
577 |
if (ipx->ipx_addr) { |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
578 |
fmd_hdl_strfree(ip_hdl, ipx->ipx_addr); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
579 |
ipx->ipx_addr = NULL; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
580 |
} |
1193 | 581 |
fmd_hdl_free(ip_hdl, ipx, sizeof (ip_xprt_t)); |
582 |
} |
|
583 |
||
584 |
/* |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
585 |
* Loop through the addresses in the connection info structure that were |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
586 |
* created by getaddrinfo() in ip_setup_addr during initialization (_fmd_init) |
1193 | 587 |
* and for each one attempt to create a socket and initialize it. If we are |
588 |
* successful, return zero. If we fail, we check ip_retry: if it is non-zero |
|
589 |
* we return the last errno and let our caller retry ip_xprt_setup() later. If |
|
590 |
* ip_retry reaches zero, we call fmd_hdl_abort() with an appropriate message. |
|
591 |
*/ |
|
592 |
static int |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
593 |
ip_xprt_setup(fmd_hdl_t *hdl, ip_cinfo_t *cinfo) |
1193 | 594 |
{ |
595 |
int err, fd, oflags, xflags, optval = 1; |
|
596 |
struct addrinfo *aip; |
|
597 |
const char *s1, *s2; |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
598 |
struct addrinfo *ail = cinfo->ipc_addr; |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
599 |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
600 |
ip_debug(IP_DEBUG_FINER, "Enter ip_xprt_setup %s\n", |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
601 |
cinfo->ipc_name == NULL ? "localhost" : cinfo->ipc_name); |
1193 | 602 |
|
9120
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
603 |
/* |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
604 |
* Set up flags as specified in the .conf file. Note that these are |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
605 |
* mostly only used for testing purposes, allowing the transport to |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
606 |
* be set up in various modes. |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
607 |
*/ |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
608 |
xflags = (ip_rdonly == FMD_B_TRUE) ? FMD_XPRT_RDONLY : FMD_XPRT_RDWR; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
609 |
if (cinfo->ipc_accept) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
610 |
xflags |= FMD_XPRT_ACCEPT; |
9120
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
611 |
if (ip_external == FMD_B_TRUE) |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
612 |
xflags |= FMD_XPRT_EXTERNAL; |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
613 |
if (ip_no_remote_repair == FMD_B_TRUE) |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
614 |
xflags |= FMD_XPRT_NO_REMOTE_REPAIR; |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
615 |
if (ip_hconly == FMD_B_TRUE) |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
616 |
xflags |= FMD_XPRT_HCONLY; |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
617 |
if (ip_hc_present_only == FMD_B_TRUE) |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
618 |
xflags |= FMD_XPRT_HC_PRESENT_ONLY; |
1193 | 619 |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
620 |
for (aip = ail; aip != NULL; aip = aip->ai_next) { |
1193 | 621 |
if (aip->ai_family != AF_INET && aip->ai_family != AF_INET6) |
622 |
continue; /* ignore anything that isn't IPv4 or IPv6 */ |
|
623 |
||
624 |
if ((fd = socket(aip->ai_family, |
|
625 |
aip->ai_socktype, aip->ai_protocol)) == -1) { |
|
626 |
err = errno; |
|
627 |
continue; |
|
628 |
} |
|
629 |
||
630 |
oflags = fcntl(fd, F_GETFL, 0); |
|
631 |
(void) fcntl(fd, F_SETFL, oflags | O_NONBLOCK); |
|
632 |
||
633 |
if (xflags & FMD_XPRT_ACCEPT) { |
|
634 |
err = setsockopt(fd, SOL_SOCKET, |
|
635 |
SO_REUSEADDR, &optval, sizeof (optval)) != 0 || |
|
636 |
bind(fd, aip->ai_addr, aip->ai_addrlen) != 0 || |
|
637 |
listen(fd, ip_qlen) != 0; |
|
638 |
} else { |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
639 |
err = connect(fd, aip->ai_addr, aip->ai_addrlen); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
640 |
if (err) |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
641 |
err = errno; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
642 |
if (err == EINPROGRESS) |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
643 |
err = 0; |
1193 | 644 |
} |
645 |
||
646 |
if (err == 0) { |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
647 |
ip_xprt_create(NULL, fd, xflags, cinfo, NULL); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
648 |
ip_debug(IP_DEBUG_FINER, "Exit ip_xprt_setup"); |
1193 | 649 |
return (0); |
650 |
} |
|
651 |
||
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
652 |
ip_debug(IP_DEBUG_FINE, "Error=%d errno=%d", err, errno); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
653 |
|
1193 | 654 |
err = errno; |
655 |
(void) close(fd); |
|
656 |
} |
|
657 |
||
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
658 |
if (cinfo->ipc_name != NULL) { |
1193 | 659 |
s1 = "failed to connect to"; |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
660 |
s2 = cinfo->ipc_name; |
1193 | 661 |
} else { |
662 |
s1 = "failed to listen on"; |
|
663 |
s2 = ip_port; |
|
664 |
} |
|
665 |
||
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
666 |
if (err == EACCES || cinfo->ipc_retry-- == 0) |
1193 | 667 |
fmd_hdl_abort(hdl, "%s %s: %s\n", s1, s2, strerror(err)); |
668 |
||
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
669 |
ip_debug(IP_DEBUG_FINE, "%s %s: %s (will retry)\n", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
670 |
s1, s2, strerror(err)); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
671 |
ip_debug(IP_DEBUG_FINER, "Exit ip_xprt_setup"); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
672 |
return (err); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
673 |
} |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
674 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
675 |
/* |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
676 |
* Free address based resources |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
677 |
*/ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
678 |
static void |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
679 |
ip_addr_cleanup() |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
680 |
{ |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
681 |
ip_cinfo_t *conn; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
682 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
683 |
(void) pthread_mutex_lock(&ip_conns_lock); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
684 |
conn = ip_conns; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
685 |
while (conn != NULL) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
686 |
ip_conns = conn->ipc_next; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
687 |
if (conn->ipc_addr != NULL) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
688 |
freeaddrinfo(conn->ipc_addr); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
689 |
conn->ipc_addr = NULL; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
690 |
if (conn->ipc_timer) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
691 |
fmd_timer_remove(ip_hdl, conn->ipc_timer); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
692 |
fmd_hdl_strfree(ip_hdl, conn->ipc_name); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
693 |
fmd_hdl_free(ip_hdl, conn, sizeof (ip_cinfo_t)); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
694 |
conn = ip_conns; |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
695 |
} |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
696 |
(void) pthread_mutex_unlock(&ip_conns_lock); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
697 |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
698 |
fmd_prop_free_string(ip_hdl, ip_port); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
699 |
} |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
700 |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
701 |
static boolean_t |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
702 |
ip_argis_cinfo(void *arg) |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
703 |
{ |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
704 |
boolean_t exists = B_FALSE; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
705 |
ip_cinfo_t *conn; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
706 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
707 |
(void) pthread_mutex_lock(&ip_conns_lock); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
708 |
for (conn = ip_conns; conn != NULL; conn = conn->ipc_next) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
709 |
if (conn == arg) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
710 |
exists = B_TRUE; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
711 |
break; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
712 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
713 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
714 |
(void) pthread_mutex_unlock(&ip_conns_lock); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
715 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
716 |
return (exists); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
717 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
718 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
719 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
720 |
static ip_cinfo_t * |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
721 |
ip_create_cinfo(char *server, boolean_t accept) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
722 |
{ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
723 |
int err; |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
724 |
struct addrinfo aih; |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
725 |
ip_cinfo_t *cinfo = fmd_hdl_zalloc( |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
726 |
ip_hdl, sizeof (ip_cinfo_t), FMD_NOSLEEP); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
727 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
728 |
if (cinfo == NULL) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
729 |
return (NULL); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
730 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
731 |
cinfo->ipc_accept = accept; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
732 |
cinfo->ipc_retry = ip_retry; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
733 |
if (server != NULL) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
734 |
cinfo->ipc_name = fmd_hdl_strdup(ip_hdl, server, FMD_NOSLEEP); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
735 |
if (cinfo->ipc_name == NULL) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
736 |
fmd_hdl_free(ip_hdl, cinfo, sizeof (ip_cinfo_t)); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
737 |
return (NULL); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
738 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
739 |
} |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
740 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
741 |
bzero(&aih, sizeof (aih)); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
742 |
aih.ai_flags = AI_ADDRCONFIG; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
743 |
aih.ai_family = AF_UNSPEC; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
744 |
aih.ai_socktype = SOCK_STREAM; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
745 |
if (server != NULL) { |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
746 |
ip_debug(IP_DEBUG_FINE, "resolving %s:%s\n", server, ip_port); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
747 |
} else { |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
748 |
aih.ai_flags |= AI_PASSIVE; |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
749 |
cinfo->ipc_name = fmd_hdl_strdup( |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
750 |
ip_hdl, "localhost", FMD_NOSLEEP); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
751 |
if (cinfo->ipc_name == NULL) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
752 |
fmd_hdl_free(ip_hdl, cinfo, sizeof (ip_cinfo_t)); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
753 |
return (NULL); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
754 |
} |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
755 |
} |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
756 |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
757 |
err = getaddrinfo(server, ip_port, &aih, &cinfo->ipc_addr); |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
758 |
if (err != 0) { |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
759 |
fmd_hdl_error(ip_hdl, "failed to resolve host %s port %s: %s\n", |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
760 |
cinfo->ipc_name, ip_port, gai_strerror(err)); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
761 |
cinfo->ipc_addr = NULL; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
762 |
fmd_hdl_strfree(ip_hdl, cinfo->ipc_name); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
763 |
fmd_hdl_free(ip_hdl, cinfo, sizeof (ip_cinfo_t)); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
764 |
cinfo = NULL; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
765 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
766 |
return (cinfo); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
767 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
768 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
769 |
/* |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
770 |
* Setup a single ip address for ip connection. |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
771 |
* If unable to setup any of the addresses then all addresses will be cleaned up |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
772 |
* and non-zero will be returned. |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
773 |
*/ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
774 |
static int |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
775 |
ip_setup_addr(char *server, boolean_t accept) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
776 |
{ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
777 |
int err = 0; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
778 |
ip_cinfo_t *cinfo = ip_create_cinfo(server, accept); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
779 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
780 |
if (cinfo == NULL) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
781 |
ip_addr_cleanup(); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
782 |
err++; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
783 |
} else { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
784 |
(void) pthread_mutex_lock(&ip_conns_lock); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
785 |
cinfo->ipc_next = ip_conns; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
786 |
ip_conns = cinfo; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
787 |
(void) pthread_mutex_unlock(&ip_conns_lock); |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
788 |
} |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
789 |
return (err); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
790 |
} |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
791 |
|
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
792 |
/* |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
793 |
* Setup a ip addresses for an ip connection. The address can be a comma |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
794 |
* separated list of addresses as well. |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
795 |
* If unable to setup any of the addresses then all addresses will be cleaned up |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
796 |
* and non-zero will be returned. |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
797 |
*/ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
798 |
static int |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
799 |
ip_setup_addrs(char *server, boolean_t accept) |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
800 |
{ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
801 |
int err = 0; |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
802 |
char *addr = server; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
803 |
char *p; |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
804 |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
805 |
for (p = server; *p != '\0'; p++) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
806 |
if (*p == ',') { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
807 |
*p = '\0'; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
808 |
err = ip_setup_addr(addr, accept); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
809 |
*p = ','; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
810 |
if (err) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
811 |
return (err); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
812 |
addr = ++p; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
813 |
if (*addr == '\0') |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
814 |
break; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
815 |
} |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
816 |
} |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
817 |
if (*addr != '\0') { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
818 |
err = ip_setup_addr(addr, accept); |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
819 |
} |
1193 | 820 |
return (err); |
821 |
} |
|
822 |
||
823 |
/* |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
824 |
* Starts all connections for each configured network address. If there is an |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
825 |
* error starting a connection a timer will be started for a retry. |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
826 |
*/ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
827 |
static void |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
828 |
ip_start_connections() |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
829 |
{ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
830 |
ip_cinfo_t *conn; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
831 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
832 |
(void) pthread_mutex_lock(&ip_conns_lock); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
833 |
for (conn = ip_conns; conn != NULL; conn = conn->ipc_next) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
834 |
if (ip_xprt_setup(ip_hdl, conn) != 0) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
835 |
conn->ipc_timer = fmd_timer_install(ip_hdl, conn, NULL, |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
836 |
ip_sleep); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
837 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
838 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
839 |
(void) pthread_mutex_unlock(&ip_conns_lock); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
840 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
841 |
|
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
842 |
/* |
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
843 |
* Timeout handler for the transport module. We use these types of timeouts: |
1193 | 844 |
* |
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
845 |
* (a) arg is ip_cinfo_t: attempt ip_xprt_setup(), re-install timeout to retry |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
846 |
* (b) arg is ip_xprt_t, FMD_XPRT_SUSPENDED: call fmd_xprt_resume() on arg |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
847 |
* (c) arg is ip_xprt_t, !FMD_XPRT_SUSPENDED: call ip_xprt_destroy() on arg |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
848 |
* (d) arg is NULL, ignore as this shouldn't happen |
1193 | 849 |
* |
850 |
* Case (c) is required as we need to cause the module's main thread, which |
|
851 |
* runs this timeout handler, to join with the transport's auxiliary thread. |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
852 |
* If the connection is a client then a timer will be installed to retry |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
853 |
* connecting to the server. |
1193 | 854 |
*/ |
855 |
static void |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
856 |
ip_timeout(fmd_hdl_t *hdl, id_t id, void *arg) { |
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
857 |
int install_timer; |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
858 |
ip_cinfo_t *cinfo; |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
859 |
ip_xprt_t *ipx; |
1193 | 860 |
|
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
861 |
if (arg == NULL) { |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
862 |
fmd_hdl_error(hdl, "ip_timeout failed because hg arg is NULL"); |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
863 |
} else if (ip_argis_cinfo(arg)) { |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
864 |
ip_debug(IP_DEBUG_FINER, |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
865 |
"Enter ip_timeout (a) install new timer"); |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
866 |
cinfo = arg; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
867 |
if ((ip_xprt_setup(hdl, arg) != 0) && !ip_quit) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
868 |
cinfo->ipc_timer = fmd_timer_install( |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
869 |
hdl, cinfo, NULL, ip_sleep); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
870 |
else |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
871 |
cinfo->ipc_timer = NULL; |
1193 | 872 |
} else { |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
873 |
ipx = arg; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
874 |
if (ipx->ipx_flags & FMD_XPRT_SUSPENDED) { |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
875 |
ipx->ipx_spnd_timer = NULL; |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
876 |
ip_debug(IP_DEBUG_FINE, "timer %d waking ipx %p", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
877 |
(int)id, arg); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
878 |
ipx->ipx_flags &= ~FMD_XPRT_SUSPENDED; |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
879 |
fmd_xprt_resume(hdl, ipx->ipx_xprt); |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
880 |
} else { |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
881 |
ip_debug(IP_DEBUG_FINE, "timer %d closing ipx %p", |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
882 |
(int)id, arg); |
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
883 |
cinfo = ipx->ipx_cinfo; |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
884 |
install_timer = (ipx->ipx_flags & FMD_XPRT_ACCEPT) != |
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
885 |
FMD_XPRT_ACCEPT; |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
886 |
ip_xprt_destroy(ipx); |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
887 |
if (install_timer && !ip_quit) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
888 |
cinfo->ipc_timer = fmd_timer_install( |
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
889 |
hdl, cinfo, NULL, ip_sleep); |
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
890 |
else |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
891 |
cinfo->ipc_timer = NULL; |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
892 |
} |
1193 | 893 |
} |
894 |
} |
|
895 |
||
896 |
static const fmd_prop_t fmd_props[] = { |
|
897 |
{ "ip_authority", FMD_TYPE_STRING, NULL }, |
|
898 |
{ "ip_bufsize", FMD_TYPE_SIZE, "4k" }, |
|
899 |
{ "ip_burp", FMD_TYPE_TIME, "0" }, |
|
900 |
{ "ip_enable", FMD_TYPE_BOOL, "false" }, |
|
901 |
{ "ip_mtbf", FMD_TYPE_INT32, "0" }, |
|
9120
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
902 |
{ "ip_external", FMD_TYPE_BOOL, "true" }, |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
903 |
{ "ip_no_remote_repair", FMD_TYPE_BOOL, "true" }, |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
904 |
{ "ip_hconly", FMD_TYPE_BOOL, "false" }, |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
905 |
{ "ip_rdonly", FMD_TYPE_BOOL, "false" }, |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
906 |
{ "ip_hc_present_only", FMD_TYPE_BOOL, "false" }, |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
907 |
{ "ip_domain_name", FMD_TYPE_STRING, NULL }, |
1193 | 908 |
{ "ip_port", FMD_TYPE_STRING, "664" }, |
909 |
{ "ip_qlen", FMD_TYPE_INT32, "32" }, |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
910 |
{ "ip_retry", FMD_TYPE_INT32, "-1" }, /* -1=forever */ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
911 |
{ "ip_server", FMD_TYPE_STRING, NULL }, /* server name */ |
1193 | 912 |
{ "ip_sleep", FMD_TYPE_TIME, "10s" }, |
913 |
{ "ip_translate", FMD_TYPE_BOOL, "false" }, |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
914 |
{ "ip_bind_addr", FMD_TYPE_STRING, NULL }, /* network interface addr */ |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
915 |
{ "ip_debug_level", FMD_TYPE_INT32, "1" }, /* debug levels 0-3 */ |
1193 | 916 |
{ NULL, 0, NULL } |
917 |
}; |
|
918 |
||
919 |
static const fmd_hdl_ops_t fmd_ops = { |
|
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
920 |
ip_fmdo_recv, /* fmdo_recv */ |
1193 | 921 |
ip_timeout, /* fmdo_timeout */ |
922 |
NULL, /* fmdo_close */ |
|
923 |
NULL, /* fmdo_stats */ |
|
924 |
NULL, /* fmdo_gc */ |
|
12307
eed67f0e6b33
6946765 ip transport needs an fmdo_recv entry point
James Kremer <James.Kremer@Sun.COM>
parents:
12142
diff
changeset
|
925 |
ip_fmdo_send, /* fmdo_send */ |
1193 | 926 |
}; |
927 |
||
928 |
static const fmd_hdl_info_t fmd_info = { |
|
929 |
"IP Transport Agent", "1.0", &fmd_ops, fmd_props |
|
930 |
}; |
|
931 |
||
932 |
/* |
|
933 |
* Initialize the ip-transport module as either a server or a client. Note |
|
934 |
* that the ip-transport module is not enabled by default under Solaris: |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
935 |
* at present we require a developer or tool to "setprop ip_enable true". |
1193 | 936 |
* If ip-transport is needed in the future out-of-the-box on one or more Sun |
937 |
* platforms, the code to check 'ip_enable' should be replaced with: |
|
938 |
* |
|
939 |
* (a) configuring ip-transport to operate in client mode by default, |
|
940 |
* (b) a platform-specific configuration mechanism, or |
|
941 |
* (c) a means to assure security and prevent denial-of-service attacks. |
|
942 |
* |
|
943 |
* Note that (c) is only an issue when the transport module operates |
|
944 |
* in server mode (i.e. with the ip_server property set to NULL) on a |
|
945 |
* generic Solaris system which may be exposed directly to the Internet. |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
946 |
* The property ip_bind_addr can be used to define a private network interface |
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
947 |
* to use so that the service is not exposed to the Internet. |
1193 | 948 |
*/ |
949 |
void |
|
950 |
_fmd_init(fmd_hdl_t *hdl) |
|
951 |
{ |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
952 |
char *addr, *auth, *p, *q, *r, *s; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
953 |
int err; |
1193 | 954 |
|
955 |
if (fmd_hdl_register(hdl, FMD_API_VERSION, &fmd_info) != 0) |
|
956 |
return; /* failed to register handle */ |
|
957 |
||
958 |
if (fmd_prop_get_int32(hdl, "ip_enable") == FMD_B_FALSE) { |
|
959 |
fmd_hdl_unregister(hdl); |
|
960 |
return; |
|
961 |
} |
|
962 |
||
963 |
(void) fmd_stat_create(hdl, FMD_STAT_NOALLOC, |
|
964 |
sizeof (ip_stat) / sizeof (fmd_stat_t), (fmd_stat_t *)&ip_stat); |
|
965 |
||
966 |
ip_hdl = hdl; |
|
967 |
(void) pthread_mutex_init(&ip_lock, NULL); |
|
968 |
||
969 |
ip_burp = fmd_prop_get_int64(hdl, "ip_burp"); |
|
970 |
ip_mtbf = fmd_prop_get_int32(hdl, "ip_mtbf"); |
|
9120
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
971 |
ip_external = fmd_prop_get_int32(hdl, "ip_external"); |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
972 |
ip_no_remote_repair = fmd_prop_get_int32(hdl, "ip_no_remote_repair"); |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
973 |
ip_hconly = fmd_prop_get_int32(hdl, "ip_hconly"); |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
974 |
ip_rdonly = fmd_prop_get_int32(hdl, "ip_rdonly"); |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
975 |
ip_hc_present_only = fmd_prop_get_int32(hdl, "ip_hc_present_only"); |
fe1f7d8cd967
6533823 need better way of proxying faults across event transport
Stephen Hanson <Stephen.Hanson@Sun.COM>
parents:
1570
diff
changeset
|
976 |
ip_domain_name = fmd_prop_get_string(hdl, "ip_domain_name"); |
1193 | 977 |
ip_qlen = fmd_prop_get_int32(hdl, "ip_qlen"); |
978 |
ip_retry = fmd_prop_get_int32(hdl, "ip_retry"); |
|
979 |
ip_sleep = fmd_prop_get_int64(hdl, "ip_sleep"); |
|
980 |
ip_translate = fmd_prop_get_int32(hdl, "ip_translate"); |
|
981 |
||
982 |
ip_size = (size_t)fmd_prop_get_int64(hdl, "ip_bufsize"); |
|
983 |
ip_size = MAX(ip_size, sizeof (ip_hdr_t)); |
|
984 |
ip_port = fmd_prop_get_string(hdl, "ip_port"); |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
985 |
ip_debug_level = fmd_prop_get_int32(hdl, "ip_debug_level"); |
1193 | 986 |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
987 |
ip_conns = NULL; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
988 |
addr = fmd_prop_get_string(hdl, "ip_bind_addr"); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
989 |
if (addr != NULL) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
990 |
err = ip_setup_addrs(addr, B_TRUE); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
991 |
if (err) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
992 |
fmd_hdl_abort(hdl, "Unable to setup ip_bind_addr %s", |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
993 |
addr); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
994 |
return; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
995 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
996 |
fmd_prop_free_string(hdl, addr); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
997 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
998 |
addr = fmd_prop_get_string(hdl, "ip_server"); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
999 |
if (addr != NULL) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1000 |
err = ip_setup_addrs(addr, B_FALSE); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1001 |
if (err) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1002 |
fmd_hdl_abort(hdl, "Unable to setup ip_server %s", |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1003 |
addr); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1004 |
return; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1005 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1006 |
fmd_prop_free_string(hdl, addr); |
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
1007 |
} |
1193 | 1008 |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1009 |
/* |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1010 |
* If no specific connecitons configured then set up general server |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1011 |
* listening on all network ports. |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1012 |
*/ |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1013 |
if (ip_conns == NULL) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1014 |
if (ip_setup_addr(NULL, B_TRUE) != 0) { |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1015 |
fmd_hdl_abort(hdl, "Unable to setup server."); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1016 |
return; |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1017 |
} |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1018 |
} |
1193 | 1019 |
|
1020 |
/* |
|
1021 |
* If ip_authority is set, tokenize this string and turn it into an |
|
1022 |
* FMA authority represented as a name-value pair list. We will use |
|
1023 |
* this authority for all transports created by this module. If |
|
1024 |
* ip_authority isn't set, we'll compute authorities on the fly. |
|
1025 |
*/ |
|
1026 |
if ((auth = fmd_prop_get_string(hdl, "ip_authority")) != NULL) { |
|
1027 |
(void) nvlist_alloc(&ip_auth, 0, 0); |
|
1028 |
(void) nvlist_add_uint8(ip_auth, |
|
1029 |
FM_VERSION, FM_FMRI_AUTH_VERSION); |
|
1030 |
||
1031 |
s = alloca(strlen(auth) + 1); |
|
1032 |
(void) strcpy(s, auth); |
|
1033 |
fmd_prop_free_string(hdl, auth); |
|
1034 |
||
1035 |
for (p = strtok_r(s, ",", &q); p != NULL; |
|
1036 |
p = strtok_r(NULL, ",", &q)) { |
|
1037 |
||
1038 |
if ((r = strchr(p, '=')) == NULL) { |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
1039 |
ip_addr_cleanup(); |
1193 | 1040 |
fmd_hdl_abort(hdl, "ip_authority element <%s> " |
1041 |
"must be in <name>=<value> form\n", p); |
|
1042 |
} |
|
1043 |
||
1044 |
*r = '\0'; |
|
1045 |
(void) nvlist_add_string(ip_auth, p, r + 1); |
|
1046 |
*r = '='; |
|
1047 |
} |
|
1048 |
} |
|
1049 |
||
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1050 |
ip_start_connections(); |
1193 | 1051 |
} |
1052 |
||
1053 |
void |
|
1054 |
_fmd_fini(fmd_hdl_t *hdl) |
|
1055 |
{ |
|
1056 |
ip_quit++; /* set quit flag before signalling auxiliary threads */ |
|
1057 |
||
1058 |
while (ip_xps != NULL) |
|
1059 |
ip_xprt_destroy(ip_xps); |
|
1060 |
||
1061 |
if (ip_auth != NULL) |
|
1062 |
nvlist_free(ip_auth); |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1063 |
|
12142
3f12f631c1a8
6901394 ip-transport module needs to get ready for the big time
James Kremer <James.Kremer@Sun.COM>
parents:
9120
diff
changeset
|
1064 |
ip_addr_cleanup(); |
1193 | 1065 |
|
12581
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1066 |
if (ip_domain_name != NULL) |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1067 |
fmd_prop_free_string(ip_hdl, ip_domain_name); |
18307efc4636
6954030 IP Transport with multiple loopback connections
James Kremer <James.Kremer@Sun.COM>
parents:
12307
diff
changeset
|
1068 |
|
1193 | 1069 |
fmd_hdl_unregister(hdl); |
1070 |
} |