Chinaunix首页 | 论坛 | 博客
  • 博客访问: 54707
  • 博文数量: 4
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 67
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-22 13:29
文章分类

全部博文(4)

文章存档

2015年(4)

我的朋友

分类: 虚拟化

2015-05-29 13:43:55

        在Linux 协议咱中引入了net namespace 后既已支持了多个实例,包含在net namespace 中元素有:进程、套接字、网络设备、proc文件
        We create a mechanism that from the users perspective allows creation of separate instances of the network stack.
        在linux 中命名空间的结构体为struct net,存在于linux/include/net/net_namespace.h
        

点击(此处)折叠或打开

  1. struct net {
  2.     atomic_t        passive;    /* To decided when the network
  3.                          * namespace should be freed.
  4.                          */
  5.     atomic_t        count;        /* To decided when the network
  6.                          * namespace should be shut down.
  7.                          */
  8. #ifdef NETNS_REFCNT_DEBUG
  9.     atomic_t        use_count;    /* To track references we
  10.                          * destroy on demand
  11.                          */
  12. #endif
  13.     spinlock_t        rules_mod_lock;

  14.     struct list_head    list;        /* list of network namespaces */
  15.     struct list_head    cleanup_list;    /* namespaces on death row */
  16.     struct list_head    exit_list;    /* Use only net_mutex */

  17.     struct user_namespace *user_ns;    /* Owning user namespace */

  18.     unsigned int        proc_inum;

  19.     struct proc_dir_entry     *proc_net;
  20.     struct proc_dir_entry     *proc_net_stat;

  21. #ifdef CONFIG_SYSCTL
  22.     struct ctl_table_set    sysctls;
  23. #endif

  24.     struct sock         *rtnl;            /* rtnetlink socket */
  25.     struct sock        *genl_sock;

  26.     struct list_head     dev_base_head;
  27.     struct hlist_head     *dev_name_head;
  28.     struct hlist_head    *dev_index_head;
  29.     unsigned int        dev_base_seq;    /* protected by rtnl_mutex */
  30.     int            ifindex;
  31.     unsigned int        dev_unreg_count;

  32.     /* core fib_rules */
  33.     struct list_head    rules_ops;


  34.     struct net_device *loopback_dev; /* The loopback */
  35.     struct netns_core    core;
  36.     struct netns_mib    mib;
  37.     struct netns_packet    packet;
  38.     struct netns_unix    unx;
  39.     struct netns_ipv4    ipv4;
  40. #if IS_ENABLED(CONFIG_IPV6)
  41.     struct netns_ipv6    ipv6;
  42. #endif
  43. #if IS_ENABLED(CONFIG_IEEE802154_6LOWPAN)
  44.     struct netns_ieee802154_lowpan    ieee802154_lowpan;
  45. #endif
  46. #if defined(CONFIG_IP_SCTP) || defined(CONFIG_IP_SCTP_MODULE)
  47.     struct netns_sctp    sctp;
  48. #endif
  49. #if defined(CONFIG_IP_DCCP) || defined(CONFIG_IP_DCCP_MODULE)
  50.     struct netns_dccp    dccp;
  51. #endif
  52. #ifdef CONFIG_NETFILTER
  53.     struct netns_nf        nf;
  54.     struct netns_xt        xt;
  55. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  56.     struct netns_ct        ct;
  57. #endif
  58. #if defined(CONFIG_NF_TABLES) || defined(CONFIG_NF_TABLES_MODULE)
  59.     struct netns_nftables    nft;
  60. #endif
  61. #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
  62.     struct netns_nf_frag    nf_frag;
  63. #endif
  64.     struct sock        *nfnl;
  65.     struct sock        *nfnl_stash;
  66. #endif
  67. #ifdef CONFIG_WEXT_CORE
  68.     struct sk_buff_head    wext_nlevents;
  69. #endif
  70.     struct net_generic __rcu    *gen;

  71.     /* Note : following structs are cache line aligned */
  72. #ifdef CONFIG_XFRM
  73.     struct netns_xfrm    xfrm;
  74. #endif
  75. #if IS_ENABLED(CONFIG_IP_VS)
  76.     struct netns_ipvs    *ipvs;
  77. #endif
  78.     struct sock        *diag_nlsk;
  79.     atomic_t        fnhe_genid;
  80. };
        对于设备:在list_netdevice 函数中将设备分别挂到了三条链表上:
        

点击(此处)折叠或打开

  1. list_add_tail_rcu(&dev->dev_list, &net->dev_base_head);
  2. hlist_add_head_rcu(&dev->name_hlist, dev_name_hash(net, dev->name));
  3. hlist_add_head_rcu(&dev->index_hlist,dev_index_hash(net, dev->ifindex));
        同样struct net_device 也有回朔的变量 net.
        对于 net 本身而言,也被连接到了net_namespace_list 上,系统初始化的时候自动生成一个命名空间:init_net

        在用户态可以通过ip netns  对network namespace进行查看,新建,删除等操作。

Ref:
[1]
[2]
[3]
阅读(3299) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~