免费注册 查看新帖 |

Chinaunix

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

求助!!!防火墙的connlimit补丁始终打不上。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-10-05 17:19 |只看该作者 |倒序浏览
打补丁时一切正常,但是编译内核时总是提示下面的错误,无法通过。
我用的是RedhatAS4 内核版本是2.6.9 。 用的新内核是2.6.14.3
请各位高手给与指点。谢谢!

CC [M]  net/ipv4/netfilter/ipt_connlimit.o
net/ipv4/netfilter/ipt_connlimit.c: In function `count_them':
net/ipv4/netfilter/ipt_connlimit.c:74: structure has no member named `ctrack'
net/ipv4/netfilter/ipt_connlimit.c:94: structure has no member named `ctrack'
net/ipv4/netfilter/ipt_connlimit.c:100: structure has no member named `ctrack'
net/ipv4/netfilter/ipt_connlimit.c:107: structure has no member named `ctrack'
make[3]: *** [net/ipv4/netfilter/ipt_connlimit.o] Error 1
make[2]: *** [net/ipv4/netfilter] Error 2

论坛徽章:
0
2 [报告]
发表于 2006-10-05 19:16 |只看该作者
你打补丁的过程出错了.把你打补丁的过程贴出来

论坛徽章:
0
3 [报告]
发表于 2006-10-05 22:01 |只看该作者
谢谢,我现在在朋友家,明晚回家后贴出来.请多指教.

论坛徽章:
0
4 [报告]
发表于 2006-10-05 23:29 |只看该作者
原帖由 Aqie 于 2006-10-5 19:16 发表
你打补丁的过程出错了

同感

论坛徽章:
0
5 [报告]
发表于 2006-10-07 10:29 |只看该作者
其余补丁都没有打,只是打了connlinit一个补丁。

Testing connlimit... not applied
The connlimit patch:
.................

Do you want to apply this patch  [N/y/t/f/a/rb/w/q/?] 在此我选了 y .

没有其它提示,直接显示下一个补丁。

论坛徽章:
0
6 [报告]
发表于 2006-10-07 15:44 |只看该作者
以下是我打补丁的过程:


zhwj:/usr/src/patch-o-matic-ng-20040621 # ./runame base
Hey! KERNEL_DIR is not set.
Where is your kernel source directory? [/usr/src/linux] /usr/src/linux-2.6.14.3
Hey! IPTABLES_DIR is not set .
Where is your iptables source code directory? [/usr/src/iptables] /usr/src/iptables-1.2.11

其余补丁都选 n 没有打。只打了connlimit 这一个补丁。

这是connlimit补丁:

Welcome to Patch-o-matic (1.17)!

Kernel: 2.6.14, /usr/src/linux-2.6.14.3
Iptables: 1.2.11, /usr/src/iptables-1.2.11
Each patch is a new feature: many have minimal impact, some do not.
Almost every now has bugs, so don't apply what you don't need!
--------------------------------------------------------------------------------------
Already applied:01_iptables-1.2.10.patch 01_linux-2.6.3.patch CLASSIFY_more-hooks mangle-reroute proc-no-internal-targets HOPLIMIT NETMAP SAME TTL

Testing connlimit... not applied
The connlimit patch:
  Author:Gerd Knorr <kraxel@byteses.ory>
  Status: ItWorksForMe[tm]

This adds an iptables match which allows you to restrict the
number of parallel TCP connections to a server per client IP address
(or address block).

Examples:
.................................
................................
--------------------------------------------------------------------------------------------
Do you want to apply this patch [N/y/t/f/a/r/b/w/q/?] y

最后显示:

Excellent! Source trees are ready for compilation.

[ 本帖最后由 levin2008 于 2006-10-7 16:24 编辑 ]

论坛徽章:
0
7 [报告]
发表于 2006-10-07 16:13 |只看该作者
看不到图。

论坛徽章:
0
8 [报告]
发表于 2006-10-08 17:37 |只看该作者
2.6.1X之后netfilter中的几个数据结构有变化,而connlimit是按照新版本设计的,所以在老内核会出类似的问题,我不知道你的内核版本是否已经是新版数据结构了,至少我在2.6.9上是无法正常通过编译的,错误信息貌似与你的类似,不过记不太清楚了。
以前我通过修改connlimit把那些数据结构patch掉解决过这个问题,patchfile在CU贴过,回头帮你找找看,应该可用。

论坛徽章:
0
9 [报告]
发表于 2006-10-08 17:42 |只看该作者
查到了,不过应该是connlimit是2.6.11之后可以用的,如果你的内核版本如你所说,不应该出问题才对。
还是把patchfile贴出来吧。


--- BUILD-connlimit/ipt_connlimit.c.RH 2005-07-04 20:53:55.000000000 +0200
+++ BUILD-connlimit/ipt_connlimit.c 2005-07-04 20:56:12.619285450 +0200
@@ -63,9 +63,9 @@
for (lh = hash->next; lh != hash; lh = lh->next) {
conn = list_entry(lh,struct ipt_connlimit_conn,list);
found = ip_conntrack_find_get(&conn->tuple,ct);
- if (found != NULL &&
- 0 == memcmp(&conn->tuple,&tuple,sizeof(tuple)) &&
- found->ctrack->proto.tcp.state != TCP_CONNTRACK_TIME_WAIT) {
+ if (found != NULL
+ && 0 == memcmp(&conn->tuple,&tuple,sizeof(tuple))
+ && found->ctrack->proto.tcp.state != TCP_CONNTRACK_TIME_WAIT) {
/* Just to be sure we have it only once in the list.
We should'nt see tuples twice unless someone hooks this
into a table without "-p tcp --syn" */
@@ -91,14 +91,14 @@
lh = lh->prev;
list_del(lh->next);
kfree(conn);
- nf_conntrack_put(&found->ctrack->infos[0]);
+ nf_conntrack_put(&found->ctrack->ct_general);
continue;
}
if ((addr & mask) == (conn->tuple.src.ip & mask)) {
/* same source IP address -> be counted! */
matches++;
}
- nf_conntrack_put(&found->ctrack->infos[0]);
+ nf_conntrack_put(&found->ctrack->ct_general);
}
if (addit) {
/* save the new connection in our list */
@@ -109,8 +109,10 @@
NIPQUAD(tuple.dst.ip), ntohs(tuple.dst.u.tcp.port));
#endif
conn = kmalloc(sizeof(*conn),GFP_ATOMIC);
if (NULL == conn) {
spin_unlock_bh(&data->lock);
return -1;
}
memset(conn,0,sizeof(*conn));
INIT_LIST_HEAD(&conn->list);
conn->tuple = tuple;
@@ -127,8 +129,6 @@
const struct net_device *out,
const void *matchinfo,
int offset,
const void *hdr,
u_int16_t datalen,
int *hotdrop)
{
const struct ipt_connlimit_info *info = matchinfo;
@@ -204,8 +204,14 @@
kfree(info->data);
}

static struct ipt_match connlimit_match = {
.list = { NULL, NULL },
.name = "connlimit",
.match = &match,
.checkentry = &check,
.destroy = &destroy,
.me = THIS_MODULE
};

static int __init init(void)
{

论坛徽章:
0
10 [报告]
发表于 2006-10-08 22:17 |只看该作者
MODULE_LICENSE("GPL" );

struct ipt_connlimit_conn]
{
           struct list_head list;
           sturct ip_conntrack_tuple tuple;
};

struct ipt_connlimit_data {
                 spinlock_t lock;
                 struct list_head iphash[256];
};

static ini ipt_iphash(u_int32_t addr)
{
            int hash;

            hash = addr         & 0xff;
            hash ^= (addr >> 8 ) & 0xff;
            hash ^= (addr >> 16) & 0xff;
            hash ^= (addr >> 24) & 0xff;
            return hash;
}

static int count_them(struct ipt_connlimit_data *data,
                                   u_int32_t addr, u_int32_t mask,
                                    struct ip_conntrack *ct)
{
          const static char *tcp[] = { "nooe", "established", "syn_sent", "syn_recv",
                                                      "fin_wait", "time_wait", "clsoe", "close_wait",
                                                       "last_ack", "listen" };

          int addit = 1, matches = 0;
          struct ip_conntrack_tuple tuple;
          struct ip_conntrack_tuple_hash *found;
          struct ipt_connlimit_conn *conn;
          struct list_head *hash, *lh;

          spin_lock(&data->lock);
          tuple = ct->tuplehash[0].tuple;
          hash = &data->iphash[ipt_iphash(addr & mask)];

/* check the saved connections */
for (lh = hash->next; lh != hash ; lh = lh->next) {
             conn = list_entry(lh,struct ipt_connlimit_conn,list);
             found = ip_conntrack_find_get(&conn->tuple,ct);
             if (0 == memcmp(&conn->tuple,&tuple,sizeof(tuple)) &&
                  found != NULL &&
                  found->ctrack->proto.tcp.state != TCP_CONNTRACK_TIME_WAIT) {
                      /*Just to be sure we have it only once in the list.
                          We should'nt see tuples twice unless someone hooks this
                          into a table without "-p tcp --syn" */
                          addit = 0;
                   }
            printk("ipt_connlimit [%d]; src=%u. %u.%u.%u:%d dst=%u.%u.%u.%u:%d %s\n" ),
                    ipt_iphash(addr & mask),
                    NIPQUAD(conn->tuple.src.ip), ntohs(conn->tuple.src.u.tcp.port),
                    NIPQUAD(conn->tuple.dst.ip), ntohs(conn->tuple.dst.u.tcp.port),
                    (NULL != found) ? tcp[found->ctrack->proto.tcp.state] : "gone" );
             if  (NULL == found) {
                    /* this one is gone */
                      lh = lh->prev;
                      list_del(lh->next);
                      kfree(conn);
                      continue;
                     }
                      if (found->ctrack->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT) {
                       lh = lh->prev;
                       list_del(lh->next);
                       kfree(conn);
                       nf_conntrack_put(&found->ctrack->infos[0]);
                       continue;
          }
           if ((addr & mask) == (conn->tuple.src.ip & mask)) {
                      matches++;
           }
            nf_conntrack_put(&fonund->ctrack->infos[0]);
     }
     if (addit) {
         printk("ipt_connlimit [%d]: src=%u.%u.%u.%u:%d dst=%u.%u.%u.u:%d new\n" ),      
                     ipt_iphash(addr & mask),
                     NIPQUAD(tuple.src.ip), ntohs(tuple.src.u.tcp.port),
                     NIPQUAD(tuple.dst.ip), ntohs(tuple.dst.u.tcp.port));
         conn = kmalloc(sizeof(*conn),GFP_ATOMIC);
          if (NULL == conn)
                        return -1;
          memset(conn,0,sizeof(*conn));
          INIT_LIST_HEAD(&conn->list);
          conn->tuple = tuple;
          list_add(&conn->list,hash);
          matches++;
      }
      spin_unlock(&data->lock);
      return matches;
}

static int
match(const struct sk_buff *skb,
           const struct net_device *in,
           const struct net_device *out,
           const void *matchinfo,
           int offset,
           int *hotdrop)
{

          const struct ipt_connlimit_info *info = matchinfo;
          int connections, match;
          struct ip_conntrack *ct;
          enum ip_conntrack_info ctinfo;

          ct = ip_conntrack_get ((struct sk_buff *)skb, &ctinfo);
          if (NULL == ct ) {
                       printk("ipt_connlimit: 0ops: invalid ct state ?\n" );
                        *hotdrop = 1;
                          return 0;
          }
           connections = count_them(info->data,skb->nh.iph->saddr,info->mask,ct);
           if (-1 == connections) {
                   printk("ipt_connlimit: Hmm,kmalloc failed "-(\n" );
                    *hotdrop = 1;
                     return 0;
          }
           match = (info->inverse) ? (connections <= info->limit) : (connections > info->limit);
           printk("ipt_connlimit: src=%u.%u.%u.%u mask=%u.%u.%u.%u"
                     "connections=%d limit=%d match%s\n",
                      NIPQUAD(skb->nh.iph->saddr), NIPQUAD(INFO->mask),
                      connections, info->limit,match ? "yes" : "no" );
         return match;
}

static int check(const char *tablename,
                       const struct ipt_ip *ip,
                       void *matchinfo,
                       unsigned int matchsize,
                       unsigned int hook_mask)
{
             struct ipt_connlimit_info *info = matchinfo;
             int i;
             if (matchsize != IPT_ALIGN(sizeof(struct ipt_connlimit_info)))
                       return 0;
             if (ip->proto != IPPROTO_TCP)
                          return 0;
             info->data = kmalloc(sizeof(struct ipt_connlimit_data),GFP_KERNEL);
             spin_lock_init(&info->data->lock));
             for (i = 0; i < 256; i++)
             INIT_LIST_HEAD(&info->data->iphash));
        return 1;
}

static void destroy(void *matchinfo, unsigned int matchinfosize)
{
            struct ipt_connlimit_info *info = matchinfo;
            struct ipt_connlimit_conn *conn;
            struct list_head *hash;
            int i;
            
            for (i = 0; i < 256; i++) {
                      hash = &(info->data->iphash);
                      while = (hash != hash->next) {
                                    conn = list_entry(hash->next,struct ipt_connlimit_conn,list);
                                    list_del(hash->next);
                                    kfree(conn);
                      }
         }
          kfree(info->data);
}


static struct ipt_match connlimit_match = {
              .name = "connlimit",
              .match = &match,
              .checkentry = &check,
              .destroy = &destroy,
              .me = THIS_MODULE
};

static int __init init(void)
{
            return ipt_register_match(&connlimit_match);
}

module_init(init);
module_exit(fini);

[ 本帖最后由 levin2008 于 2006-10-8 22:25 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP