All of lore.kernel.org
 help / color / mirror / Atom feed
From: Phil Oester <kernel@linuxace.com>
To: netfilter-devel@lists.netfilter.org
Subject: [PATCH] proto_to_name duplication
Date: Fri, 21 Jul 2006 15:56:12 -0700	[thread overview]
Message-ID: <20060721225612.GA3951@linuxace.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 346 bytes --]

Update multiport match to use the iptables version of proto_to_name
instead of reinventing the wheel.

I looked at a similar ipv6 cleanup, but the ipv6header header match
makes this somewhat trickier.

Incidentally - it's probably time to remove the superfluous mport
match.  Anyone still using it can probably stick with older userspace.

Phil


[-- Attachment #2: patch-proto_to_name --]
[-- Type: text/plain, Size: 2142 bytes --]

diff -ru ipt-orig/extensions/libipt_multiport.c ipt-new/extensions/libipt_multiport.c
--- ipt-orig/extensions/libipt_multiport.c	2006-07-20 10:01:54.000000000 -0700
+++ ipt-new/extensions/libipt_multiport.c	2006-07-21 14:58:53.000000000 -0700
@@ -51,23 +51,6 @@
 	{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 unsigned int
 parse_multi_ports(const char *portstring, u_int16_t *ports, const char *proto)
 {
@@ -143,7 +126,7 @@
 		exit_error(PARAMETER_PROBLEM,
 			   "multiport only works with TCP or UDP");
 
-	if ((proto = proto_to_name(entry->ip.proto)) != NULL)
+	if ((proto = proto_to_name(entry->ip.proto, 1)) != NULL)
 		return proto;
 	else if (!entry->ip.proto)
 		exit_error(PARAMETER_PROBLEM,
@@ -264,7 +247,7 @@
 {
 	struct servent *service;
 
-	if ((service = getservbyport(htons(port), proto_to_name(proto))))
+	if ((service = getservbyport(htons(port), proto_to_name(proto, 1))))
 		return service->s_name;
 
 	return NULL;
diff -ru ipt-orig/include/iptables.h ipt-new/include/iptables.h
--- ipt-orig/include/iptables.h	2006-07-20 10:01:54.000000000 -0700
+++ ipt-new/include/iptables.h	2006-07-21 15:29:18.000000000 -0700
@@ -151,6 +151,7 @@
 extern void register_match(struct iptables_match *me);
 extern void register_target(struct iptables_target *me);
 
+extern char *proto_to_name(u_int8_t proto, int nolookup);
 extern int service_to_port(const char *name, const char *proto);
 extern u_int16_t parse_port(const char *port, const char *proto);
 extern struct in_addr *dotted_to_addr(const char *dotted);
diff -ru ipt-orig/iptables.c ipt-new/iptables.c
--- ipt-orig/iptables.c	2006-07-20 10:01:54.000000000 -0700
+++ ipt-new/iptables.c	2006-07-21 15:29:28.000000000 -0700
@@ -229,9 +229,10 @@
 	{ "esp", IPPROTO_ESP },
 	{ "ah", IPPROTO_AH },
 	{ "sctp", IPPROTO_SCTP },
+	{ "dccp", IPPROTO_DCCP },
 };
 
-static char *
+char *
 proto_to_name(u_int8_t proto, int nolookup)
 {
 	unsigned int i;

             reply	other threads:[~2006-07-21 22:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-21 22:56 Phil Oester [this message]
2006-07-22 13:47 ` [PATCH] proto_to_name duplication Patrick McHardy
2006-07-22 16:39   ` Phil Oester
2006-07-24  5:38   ` Yasuyuki KOZAKAI
2006-07-24 14:49     ` Phil Oester
2006-07-25  1:21       ` Patrick McHardy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060721225612.GA3951@linuxace.com \
    --to=kernel@linuxace.com \
    --cc=netfilter-devel@lists.netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.