Lines Matching +full:network +full:- +full:oriented

1 // SPDX-License-Identifier: GPL-2.0
61 const int noresvport; /* use non-priv port */
62 struct net *net; /* network namespace to bind */
67 * Hash function must work well on big- and little-endian platforms
78 return __nlm_hash32(sin->sin_addr.s_addr); in __nlm_hash_addr4()
84 const struct in6_addr addr = sin6->sin6_addr; in __nlm_hash_addr6()
95 switch (sap->sa_family) { in nlm_hash_address()
105 return hash & (NLM_HOST_NRHASH - 1); in nlm_hash_address()
118 refcount_inc(&nsm->sm_count); in nlm_alloc_host()
120 nsm = nsm_get_handle(ni->net, ni->sap, ni->salen, in nlm_alloc_host()
121 ni->hostname, ni->hostname_len); in nlm_alloc_host()
136 memcpy(nlm_addr(host), ni->sap, ni->salen); in nlm_alloc_host()
137 host->h_addrlen = ni->salen; in nlm_alloc_host()
139 host->h_srcaddrlen = 0; in nlm_alloc_host()
141 host->h_rpcclnt = NULL; in nlm_alloc_host()
142 host->h_name = nsm->sm_name; in nlm_alloc_host()
143 host->h_version = ni->version; in nlm_alloc_host()
144 host->h_proto = ni->protocol; in nlm_alloc_host()
145 host->h_reclaiming = 0; in nlm_alloc_host()
146 host->h_server = ni->server; in nlm_alloc_host()
147 host->h_noresvport = ni->noresvport; in nlm_alloc_host()
148 host->h_inuse = 0; in nlm_alloc_host()
149 init_waitqueue_head(&host->h_gracewait); in nlm_alloc_host()
150 init_rwsem(&host->h_rwsem); in nlm_alloc_host()
151 host->h_state = 0; in nlm_alloc_host()
152 host->h_nsmstate = 0; in nlm_alloc_host()
153 host->h_pidcount = 0; in nlm_alloc_host()
154 refcount_set(&host->h_count, 1); in nlm_alloc_host()
155 mutex_init(&host->h_mutex); in nlm_alloc_host()
156 host->h_nextrebind = now + NLM_HOST_REBIND; in nlm_alloc_host()
157 host->h_expires = now + NLM_HOST_EXPIRE; in nlm_alloc_host()
158 INIT_LIST_HEAD(&host->h_lockowners); in nlm_alloc_host()
159 spin_lock_init(&host->h_lock); in nlm_alloc_host()
160 INIT_LIST_HEAD(&host->h_granted); in nlm_alloc_host()
161 INIT_LIST_HEAD(&host->h_reclaim); in nlm_alloc_host()
162 host->h_nsmhandle = nsm; in nlm_alloc_host()
163 host->h_addrbuf = nsm->sm_addrbuf; in nlm_alloc_host()
164 host->net = ni->net; in nlm_alloc_host()
165 host->h_cred = get_cred(ni->cred); in nlm_alloc_host()
166 strscpy(host->nodename, utsname()->nodename, sizeof(host->nodename)); in nlm_alloc_host()
180 struct lockd_net *ln = net_generic(host->net, lockd_net_id); in nlm_destroy_host_locked()
182 dprintk("lockd: destroy host %s\n", host->h_name); in nlm_destroy_host_locked()
184 hlist_del_init(&host->h_hash); in nlm_destroy_host_locked()
187 nsm_release(host->h_nsmhandle); in nlm_destroy_host_locked()
189 clnt = host->h_rpcclnt; in nlm_destroy_host_locked()
192 put_cred(host->h_cred); in nlm_destroy_host_locked()
195 ln->nrhosts--; in nlm_destroy_host_locked()
196 nrhosts--; in nlm_destroy_host_locked()
200 * nlmclnt_lookup_host - Find an NLM host handle matching a remote server
201 * @sap: network address of server
205 * @hostname: '\0'-terminated hostname of server
206 * @noresvport: 1 if non-privileged port should be used
210 * Returns an nlm_host structure that matches the passed-in
249 if (host->net != net) in nlmclnt_lookup_host()
256 nsm = host->h_nsmhandle; in nlmclnt_lookup_host()
258 if (host->h_proto != protocol) in nlmclnt_lookup_host()
260 if (host->h_version != version) in nlmclnt_lookup_host()
265 host->h_name, host->h_addrbuf); in nlmclnt_lookup_host()
273 hlist_add_head(&host->h_hash, chain); in nlmclnt_lookup_host()
274 ln->nrhosts++; in nlmclnt_lookup_host()
278 host->h_name, host->h_addrbuf); in nlmclnt_lookup_host()
286 * nlmclnt_release_host - release client nlm_host
295 dprintk("lockd: release client host %s\n", host->h_name); in nlmclnt_release_host()
297 WARN_ON_ONCE(host->h_server); in nlmclnt_release_host()
299 if (refcount_dec_and_mutex_lock(&host->h_count, &nlm_host_mutex)) { in nlmclnt_release_host()
300 WARN_ON_ONCE(!list_empty(&host->h_lockowners)); in nlmclnt_release_host()
301 WARN_ON_ONCE(!list_empty(&host->h_granted)); in nlmclnt_release_host()
302 WARN_ON_ONCE(!list_empty(&host->h_reclaim)); in nlmclnt_release_host()
310 * nlmsvc_lookup_host - Find an NLM host handle matching a remote client
316 * transport protocol, NLM version, client hostname] of the passed-in
322 * multiple network addresses. The family of the address in
335 size_t src_len = rqstp->rq_daddrlen; in nlmsvc_lookup_host()
340 .salen = rqstp->rq_addrlen, in nlmsvc_lookup_host()
341 .protocol = rqstp->rq_prot, in nlmsvc_lookup_host()
342 .version = rqstp->rq_vers, in nlmsvc_lookup_host()
350 (int)hostname_len, hostname, rqstp->rq_vers, in nlmsvc_lookup_host()
351 (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp")); in nlmsvc_lookup_host()
355 if (time_after_eq(jiffies, ln->next_gc)) in nlmsvc_lookup_host()
360 if (host->net != net) in nlmsvc_lookup_host()
367 nsm = host->h_nsmhandle; in nlmsvc_lookup_host()
369 if (host->h_proto != ni.protocol) in nlmsvc_lookup_host()
371 if (host->h_version != ni.version) in nlmsvc_lookup_host()
377 hlist_del(&host->h_hash); in nlmsvc_lookup_host()
378 hlist_add_head(&host->h_hash, chain); in nlmsvc_lookup_host()
382 __func__, host->h_name, host->h_addrbuf); in nlmsvc_lookup_host()
391 host->h_srcaddrlen = src_len; in nlmsvc_lookup_host()
392 hlist_add_head(&host->h_hash, chain); in nlmsvc_lookup_host()
393 ln->nrhosts++; in nlmsvc_lookup_host()
396 refcount_inc(&host->h_count); in nlmsvc_lookup_host()
399 __func__, host->h_name, host->h_addrbuf); in nlmsvc_lookup_host()
407 * nlmsvc_release_host - release server nlm_host
417 dprintk("lockd: release server host %s\n", host->h_name); in nlmsvc_release_host()
419 WARN_ON_ONCE(!host->h_server); in nlmsvc_release_host()
420 refcount_dec(&host->h_count); in nlmsvc_release_host()
432 host->h_name, host->h_addrbuf); in nlm_bind_host()
435 mutex_lock(&host->h_mutex); in nlm_bind_host()
440 if ((clnt = host->h_rpcclnt) != NULL) { in nlm_bind_host()
451 .net = host->net, in nlm_bind_host()
452 .protocol = host->h_proto, in nlm_bind_host()
454 .addrsize = host->h_addrlen, in nlm_bind_host()
456 .servername = host->h_name, in nlm_bind_host()
458 .version = host->h_version, in nlm_bind_host()
463 .cred = host->h_cred, in nlm_bind_host()
471 if (!host->h_server) in nlm_bind_host()
473 if (host->h_noresvport) in nlm_bind_host()
475 if (host->h_srcaddrlen) in nlm_bind_host()
480 host->h_rpcclnt = clnt; in nlm_bind_host()
482 printk("lockd: couldn't create RPC handle for %s\n", host->h_name); in nlm_bind_host()
487 mutex_unlock(&host->h_mutex); in nlm_bind_host()
492 * nlm_rebind_host - If needed, force a portmap lookup of the peer's lockd port
495 * This is not needed when using a connection-oriented protocol, such as TCP.
502 if (host->h_proto != IPPROTO_UDP) in nlm_rebind_host()
505 if (host->h_rpcclnt && time_after_eq(jiffies, host->h_nextrebind)) { in nlm_rebind_host()
506 rpc_force_rebind(host->h_rpcclnt); in nlm_rebind_host()
507 host->h_nextrebind = jiffies + NLM_HOST_REBIND; in nlm_rebind_host()
517 dprintk("lockd: get host %s\n", host->h_name); in nlm_get_host()
518 refcount_inc(&host->h_count); in nlm_get_host()
519 host->h_expires = jiffies + NLM_HOST_EXPIRE; in nlm_get_host()
533 if (host->h_nsmhandle == nsm in next_host_state()
534 && host->h_nsmstate != info->state) { in next_host_state()
535 host->h_nsmstate = info->state; in next_host_state()
536 host->h_state++; in next_host_state()
549 * nlm_host_rebooted - Release all resources held by rebooted host
550 * @net: network namespace
590 if (ln->nrhosts == 0) in nlm_complain_hosts()
593 net->ns.inum); in nlm_complain_hosts()
594 dprintk("lockd: %lu hosts left in net %x:\n", ln->nrhosts, in nlm_complain_hosts()
595 net->ns.inum); in nlm_complain_hosts()
604 if (net && host->net != net) in nlm_complain_hosts()
607 host->h_name, refcount_read(&host->h_count), in nlm_complain_hosts()
608 host->h_inuse, host->h_expires, host->net->ns.inum); in nlm_complain_hosts()
622 net ? net->ns.inum : 0); in nlm_shutdown_hosts_net()
624 if (net && host->net != net) in nlm_shutdown_hosts_net()
626 host->h_expires = jiffies - 1; in nlm_shutdown_hosts_net()
627 if (host->h_rpcclnt) { in nlm_shutdown_hosts_net()
628 rpc_shutdown_client(host->h_rpcclnt); in nlm_shutdown_hosts_net()
629 host->h_rpcclnt = NULL; in nlm_shutdown_hosts_net()
664 net ? net->ns.inum : 0); in nlm_gc_hosts()
666 if (net && host->net != net) in nlm_gc_hosts()
668 host->h_inuse = 0; in nlm_gc_hosts()
675 if (net && host->net != net) in nlm_gc_hosts()
677 if (host->h_inuse || time_before(jiffies, host->h_expires)) { in nlm_gc_hosts()
680 host->h_name, refcount_read(&host->h_count), in nlm_gc_hosts()
681 host->h_inuse, host->h_expires, in nlm_gc_hosts()
682 host->net->ns.inum); in nlm_gc_hosts()
685 if (refcount_dec_if_one(&host->h_count)) in nlm_gc_hosts()
692 ln->next_gc = jiffies + NLM_HOST_COLLECT; in nlm_gc_hosts()