免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1430 | 回复: 3
打印 上一主题 下一主题

[网络子系统] iptables的问题 [复制链接]

论坛徽章:
1
lufei
日期:2016-06-17 17:49:16
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-08-21 20:03 |只看该作者 |倒序浏览
注册表的函数:
struct xt_table *xt_register_table(struct net *net,
                                   const struct xt_table *input_table,
                                   struct xt_table_info *bootstrap,
                                   struct xt_table_info *newinfo)
{
        int ret;
        struct xt_table_info *private;
        struct xt_table *t, *table;

        /* Don't add one object to multiple lists. */
        table = kmemdup(input_table, sizeof(struct xt_table), GFP_KERNEL);
        if (!table) {
                ret = -ENOMEM;
                goto out;
        }

        ret = mutex_lock_interruptible(&xt[table->af].mutex);
        if (ret != 0)
                goto out_free;

        /* Don't autoload: we'd eat our tail... */
        list_for_each_entry(t, &net->xt.tables[table->af], list) {
                if (strcmp(t->name, table->name) == 0) {
                        ret = -EEXIST;
                        goto unlock;
                }
        }

        /* Simplifies replace_table code. */
        table->private = bootstrap;

        if (!xt_replace_table(table, 0, newinfo, &ret))
                goto unlock;

        private = table->private;
        pr_debug("table->private->number = %u\n", private->number);

        /* save number of initial entries */
        private->initial_entries = private->number;

        list_add(&table->list, &net->xt.tables[table->af]);
        mutex_unlock(&xt[table->af].mutex);
        return table;

unlock:
        mutex_unlock(&xt[table->af].mutex);
out_free:
        kfree(table);
out:
        return ERR_PTR(ret);
}

红色部分为什么要lock,后面的代码是没有操作xt的。高手指点一下,没明白什么意思。

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
2 [报告]
发表于 2013-08-21 23:49 |只看该作者
回复 1# adidiaos丶丶
  1.       list_for_each_entry(t, &net->xt.tables[table->af], list) {
  2.                 if (strcmp(t->name, table->name) == 0) {
  3.                         ret = -EEXIST;
  4.                         goto unlock;
  5.                 }
  6.         }
复制代码
这段代码不是在做查找吗,找到之后要操作的。

   

论坛徽章:
1
lufei
日期:2016-06-17 17:49:16
3 [报告]
发表于 2013-08-22 11:05 |只看该作者
标红的xt和net->xt.tables[table->af]不是同一个东西吧回复 2# Godbach


   

论坛徽章:
36
IT运维版块每日发帖之星
日期:2016-04-10 06:20:00IT运维版块每日发帖之星
日期:2016-04-16 06:20:0015-16赛季CBA联赛之广东
日期:2016-04-16 19:59:32IT运维版块每日发帖之星
日期:2016-04-18 06:20:00IT运维版块每日发帖之星
日期:2016-04-19 06:20:00每日论坛发贴之星
日期:2016-04-19 06:20:00IT运维版块每日发帖之星
日期:2016-04-25 06:20:00IT运维版块每日发帖之星
日期:2016-05-06 06:20:00IT运维版块每日发帖之星
日期:2016-05-08 06:20:00IT运维版块每日发帖之星
日期:2016-05-13 06:20:00IT运维版块每日发帖之星
日期:2016-05-28 06:20:00每日论坛发贴之星
日期:2016-05-28 06:20:00
4 [报告]
发表于 2013-08-22 13:04 |只看该作者
回复 1# adidiaos丶丶
主要还是看语义。

这里要注册一个 table 的时候,实现互斥的逻辑。


   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP