|
14 | 14 |
|
15 | 15 | #include <linux/sunrpc/stats.h>
|
16 | 16 | #include <linux/sunrpc/svcsock.h>
|
| 17 | +#include <linux/sunrpc/svc_xprt.h> |
17 | 18 | #include <linux/lockd/bind.h>
|
18 | 19 | #include <linux/nfsacl.h>
|
19 | 20 | #include <linux/seq_file.h>
|
| 21 | +#include <linux/inetdevice.h> |
| 22 | +#include <net/addrconf.h> |
| 23 | +#include <net/ipv6.h> |
20 | 24 | #include <net/net_namespace.h>
|
21 | 25 | #include "nfsd.h"
|
22 | 26 | #include "cache.h"
|
@@ -306,10 +310,70 @@ static void nfsd_shutdown_net(struct net *net)
|
306 | 310 | nfsd_shutdown_generic();
|
307 | 311 | }
|
308 | 312 |
|
| 313 | +static int nfsd_inetaddr_event(struct notifier_block *this, unsigned long event, |
| 314 | + void *ptr) |
| 315 | +{ |
| 316 | + struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 317 | + struct net_device *dev = ifa->ifa_dev->dev; |
| 318 | + struct net *net = dev_net(dev); |
| 319 | + struct nfsd_net *nn = net_generic(net, nfsd_net_id); |
| 320 | + struct sockaddr_in sin; |
| 321 | + |
| 322 | + if (event != NETDEV_DOWN) |
| 323 | + goto out; |
| 324 | + |
| 325 | + if (nn->nfsd_serv) { |
| 326 | + dprintk("nfsd_inetaddr_event: removed %pI4\n", &ifa->ifa_local); |
| 327 | + sin.sin_family = AF_INET; |
| 328 | + sin.sin_addr.s_addr = ifa->ifa_local; |
| 329 | + svc_age_temp_xprts_now(nn->nfsd_serv, (struct sockaddr *)&sin); |
| 330 | + } |
| 331 | + |
| 332 | +out: |
| 333 | + return NOTIFY_DONE; |
| 334 | +} |
| 335 | + |
| 336 | +static struct notifier_block nfsd_inetaddr_notifier = { |
| 337 | + .notifier_call = nfsd_inetaddr_event, |
| 338 | +}; |
| 339 | + |
| 340 | +#if IS_ENABLED(CONFIG_IPV6) |
| 341 | +static int nfsd_inet6addr_event(struct notifier_block *this, |
| 342 | + unsigned long event, void *ptr) |
| 343 | +{ |
| 344 | + struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; |
| 345 | + struct net_device *dev = ifa->idev->dev; |
| 346 | + struct net *net = dev_net(dev); |
| 347 | + struct nfsd_net *nn = net_generic(net, nfsd_net_id); |
| 348 | + struct sockaddr_in6 sin6; |
| 349 | + |
| 350 | + if (event != NETDEV_DOWN) |
| 351 | + goto out; |
| 352 | + |
| 353 | + if (nn->nfsd_serv) { |
| 354 | + dprintk("nfsd_inet6addr_event: removed %pI6\n", &ifa->addr); |
| 355 | + sin6.sin6_family = AF_INET6; |
| 356 | + sin6.sin6_addr = ifa->addr; |
| 357 | + svc_age_temp_xprts_now(nn->nfsd_serv, (struct sockaddr *)&sin6); |
| 358 | + } |
| 359 | + |
| 360 | +out: |
| 361 | + return NOTIFY_DONE; |
| 362 | +} |
| 363 | + |
| 364 | +static struct notifier_block nfsd_inet6addr_notifier = { |
| 365 | + .notifier_call = nfsd_inet6addr_event, |
| 366 | +}; |
| 367 | +#endif |
| 368 | + |
309 | 369 | static void nfsd_last_thread(struct svc_serv *serv, struct net *net)
|
310 | 370 | {
|
311 | 371 | struct nfsd_net *nn = net_generic(net, nfsd_net_id);
|
312 | 372 |
|
| 373 | + unregister_inetaddr_notifier(&nfsd_inetaddr_notifier); |
| 374 | +#if IS_ENABLED(CONFIG_IPV6) |
| 375 | + unregister_inet6addr_notifier(&nfsd_inet6addr_notifier); |
| 376 | +#endif |
313 | 377 | /*
|
314 | 378 | * write_ports can create the server without actually starting
|
315 | 379 | * any threads--if we get shut down before any threads are
|
@@ -425,6 +489,10 @@ int nfsd_create_serv(struct net *net)
|
425 | 489 | }
|
426 | 490 |
|
427 | 491 | set_max_drc();
|
| 492 | + register_inetaddr_notifier(&nfsd_inetaddr_notifier); |
| 493 | +#if IS_ENABLED(CONFIG_IPV6) |
| 494 | + register_inet6addr_notifier(&nfsd_inet6addr_notifier); |
| 495 | +#endif |
428 | 496 | do_gettimeofday(&nn->nfssvc_boot); /* record boot time */
|
429 | 497 | return 0;
|
430 | 498 | }
|
|
0 commit comments