diff options
| -rw-r--r-- | net/core/net_namespace.c | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index b7403ff4d6c6..d4cf178bdfc7 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c | |||
| @@ -316,6 +316,28 @@ void __put_net(struct net *net) | |||
| 316 | } | 316 | } |
| 317 | EXPORT_SYMBOL_GPL(__put_net); | 317 | EXPORT_SYMBOL_GPL(__put_net); |
| 318 | 318 | ||
| 319 | struct net *get_net_ns_by_fd(int fd) | ||
| 320 | { | ||
| 321 | struct proc_inode *ei; | ||
| 322 | struct file *file; | ||
| 323 | struct net *net; | ||
| 324 | |||
| 325 | net = ERR_PTR(-EINVAL); | ||
| 326 | file = proc_ns_fget(fd); | ||
| 327 | if (!file) | ||
| 328 | goto out; | ||
| 329 | |||
| 330 | ei = PROC_I(file->f_dentry->d_inode); | ||
| 331 | if (ei->ns_ops != &netns_operations) | ||
| 332 | goto out; | ||
| 333 | |||
| 334 | net = get_net(ei->ns); | ||
| 335 | out: | ||
| 336 | if (file) | ||
| 337 | fput(file); | ||
| 338 | return net; | ||
| 339 | } | ||
| 340 | |||
| 319 | #else | 341 | #else |
| 320 | struct net *copy_net_ns(unsigned long flags, struct net *old_net) | 342 | struct net *copy_net_ns(unsigned long flags, struct net *old_net) |
| 321 | { | 343 | { |
| @@ -323,6 +345,11 @@ struct net *copy_net_ns(unsigned long flags, struct net *old_net) | |||
| 323 | return ERR_PTR(-EINVAL); | 345 | return ERR_PTR(-EINVAL); |
| 324 | return old_net; | 346 | return old_net; |
| 325 | } | 347 | } |
| 348 | |||
| 349 | struct net *get_net_ns_by_fd(int fd) | ||
| 350 | { | ||
| 351 | return ERR_PTR(-EINVAL); | ||
| 352 | } | ||
| 326 | #endif | 353 | #endif |
| 327 | 354 | ||
| 328 | struct net *get_net_ns_by_pid(pid_t pid) | 355 | struct net *get_net_ns_by_pid(pid_t pid) |
| @@ -345,28 +372,6 @@ struct net *get_net_ns_by_pid(pid_t pid) | |||
| 345 | } | 372 | } |
| 346 | EXPORT_SYMBOL_GPL(get_net_ns_by_pid); | 373 | EXPORT_SYMBOL_GPL(get_net_ns_by_pid); |
| 347 | 374 | ||
| 348 | struct net *get_net_ns_by_fd(int fd) | ||
| 349 | { | ||
| 350 | struct proc_inode *ei; | ||
| 351 | struct file *file; | ||
| 352 | struct net *net; | ||
| 353 | |||
| 354 | net = ERR_PTR(-EINVAL); | ||
| 355 | file = proc_ns_fget(fd); | ||
| 356 | if (!file) | ||
| 357 | goto out; | ||
| 358 | |||
| 359 | ei = PROC_I(file->f_dentry->d_inode); | ||
| 360 | if (ei->ns_ops != &netns_operations) | ||
| 361 | goto out; | ||
| 362 | |||
| 363 | net = get_net(ei->ns); | ||
| 364 | out: | ||
| 365 | if (file) | ||
| 366 | fput(file); | ||
| 367 | return net; | ||
| 368 | } | ||
| 369 | |||
| 370 | static int __init net_ns_init(void) | 375 | static int __init net_ns_init(void) |
| 371 | { | 376 | { |
| 372 | struct net_generic *ng; | 377 | struct net_generic *ng; |
