]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
Add DCCP/SCTP support to multiport. Patch for kernel will go in 2.6.18.
authorPatrick McHardy <kaber@trash.net>
Fri, 28 Apr 2006 08:10:08 +0000 (08:10 +0000)
committerPatrick McHardy <kaber@trash.net>
Fri, 28 Apr 2006 08:10:08 +0000 (08:10 +0000)
extensions/libip6t_multiport.c
extensions/libipt_multiport.c
include/ip6tables.h
include/iptables.h

index 013241b227f95f13c63aa6a5e49f1ac67208de55..a8a8e08ab0917be460ce5c7861fe0234de3cabb2 100644 (file)
@@ -33,6 +33,23 @@ static struct option opts[] = {
        {0}
 };
 
+static char *
+proto_to_name(u_int8_t proto)
+{
+       switch (proto) {
+       case IPPROTO_TCP:
+               return "tcp";
+       case IPPROTO_UDP:
+               return "udp";
+       case IPPROTO_SCTP:
+               return "sctp";
+       case IPPROTO_DCCP:
+               return "dccp";
+       default:
+               return NULL;
+       }
+}
+
 static int
 service_to_port(const char *name, const char *proto)
 {
@@ -86,16 +103,16 @@ init(struct ip6t_entry_match *m, unsigned int *nfcache)
 static const char *
 check_proto(const struct ip6t_entry *entry)
 {
-       if (entry->ipv6.proto == IPPROTO_TCP)
-               return "tcp";
-       else if (entry->ipv6.proto == IPPROTO_UDP)
-               return "udp";
+       char *proto;
+
+       if ((proto = proto_to_name(entry->ipv6.proto)) != NULL)
+               return proto;
        else if (!entry->ipv6.proto)
                exit_error(PARAMETER_PROBLEM,
-                          "multiport needs `-p tcp' or `-p udp'");
+                          "multiport needs `-p tcp', `-p udp', `-p sctp' or `-p dccp'");
        else
                exit_error(PARAMETER_PROBLEM,
-                          "multiport only works with TCP or UDP");
+                          "multiport only works with TCP, UDP, SCTP and DCCP");
 }
 
 /* Function which parses command options; returns true if it
@@ -163,8 +180,7 @@ port_to_service(int port, u_int8_t proto)
 {
        struct servent *service;
 
-       if ((service = getservbyport(htons(port),
-                                    proto == IPPROTO_TCP ? "tcp" : "udp")))
+       if ((service = getservbyport(htons(port), proto_to_name(proto))))
                return service->s_name;
 
        return NULL;
index 9f5193fa9b93d64176f16dee4f1b73e5d517a5d1..97e1476576f44ca8eea13c843a50f6f9a7656d62 100644 (file)
@@ -51,6 +51,23 @@ static struct option opts[] = {
        {0}
 };
 
+static char *
+proto_to_name(u_int8_t proto)
+{
+       switch (proto) {
+       case IPPROTO_TCP:
+               return "tcp";
+       case IPPROTO_UDP:
+               return "udp";
+       case IPPROTO_SCTP:
+               return "sctp";
+       case IPPROTO_DCCP:
+               return "dccp";
+       default:
+               return NULL;
+       }
+}
+
 static int
 service_to_port(const char *name, const char *proto)
 {
@@ -144,20 +161,20 @@ init(struct ipt_entry_match *m, unsigned int *nfcache)
 static const char *
 check_proto(const struct ipt_entry *entry)
 {
+       char *proto;
+
        if (entry->ip.invflags & IPT_INV_PROTO)
                exit_error(PARAMETER_PROBLEM,
                           "multiport only works with TCP or UDP");
 
-       if (entry->ip.proto == IPPROTO_TCP)
-               return "tcp";
-       else if (entry->ip.proto == IPPROTO_UDP)
-               return "udp";
+       if ((proto = proto_to_name(entry->ip.proto)) != NULL)
+               return proto;
        else if (!entry->ip.proto)
                exit_error(PARAMETER_PROBLEM,
-                          "multiport needs `-p tcp' or `-p udp'");
+                          "multiport needs `-p tcp', `-p udp', `-p sctp' or `-p dccp'");
        else
                exit_error(PARAMETER_PROBLEM,
-                          "multiport only works with TCP or UDP");
+                          "multiport only works with TCP, UDP, SCTP and DCCP");
 }
 
 /* Function which parses command options; returns true if it
@@ -271,8 +288,7 @@ port_to_service(int port, u_int8_t proto)
 {
        struct servent *service;
 
-       if ((service = getservbyport(htons(port),
-                                    proto == IPPROTO_TCP ? "tcp" : "udp")))
+       if ((service = getservbyport(htons(port), proto_to_name(proto))))
                return service->s_name;
 
        return NULL;
index d5ea878e5e322a8290c6e8b136b8d3c2353d2a66..96f9798b7bef06155bf691d4ace1d8a968ddd4b0 100644 (file)
@@ -8,6 +8,13 @@
 #define IP6T_LIB_DIR "/usr/local/lib/iptables"
 #endif
 
+#ifndef IPPROTO_SCTP
+#define IPPROTO_SCTP 132
+#endif
+#ifndef IPPROTO_DCCP
+#define IPPROTO_DCCP 33
+#endif
+
 struct ip6tables_rule_match
 {
        struct ip6tables_rule_match *next;
index c56a00571a24e8cb0be421989b051a3c84b53756..1cd9dc4196ec5fbbd3cfafca5118a44f8adaacd7 100644 (file)
@@ -11,6 +11,9 @@
 #ifndef IPPROTO_SCTP
 #define IPPROTO_SCTP 132
 #endif
+#ifndef IPPROTO_DCCP
+#define IPPROTO_DCCP 33
+#endif
 
 #ifndef IPT_SO_GET_REVISION_MATCH /* Old kernel source. */
 #define IPT_SO_GET_REVISION_MATCH      (IPT_BASE_CTL + 2)