All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] proto_to_name duplication
@ 2006-07-21 22:56 Phil Oester
  2006-07-22 13:47 ` Patrick McHardy
  0 siblings, 1 reply; 6+ messages in thread
From: Phil Oester @ 2006-07-21 22:56 UTC (permalink / raw)
  To: netfilter-devel

[-- 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;

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-07-25  1:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-21 22:56 [PATCH] proto_to_name duplication Phil Oester
2006-07-22 13:47 ` 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

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.