Linux Advanced Routing and Traffic Control list
 help / color / mirror / Atom feed
* [LARTC] set skb->priority with ping
@ 2002-04-18 15:25 Patrick McHardy
  0 siblings, 0 replies; only message in thread
From: Patrick McHardy @ 2002-04-18 15:25 UTC (permalink / raw)
  To: lartc

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

Hi !

While playing around with skb->priority i made a new option -P for ping 
to direct icmp echo packets to a particular class. It's not very useful
because it only has any effect if no filter are attached to the parent 
(at least i think so), but maybe someone else finds it useful.
The patch applies against iputils-ss020124.

Bye,
Patrick

[-- Attachment #2: ping.diff --]
[-- Type: text/plain, Size: 2076 bytes --]

--- iputils/ping.c	Sun Dec  2 19:28:32 2001
+++ iputils-prio/ping.c	Thu Apr 18 17:06:54 2002
@@ -79,6 +79,7 @@
 struct sockaddr_in whereto;	/* who to ping */
 int optlen = 0;
 int settos = 0;			/* Set TOS, Precendence or other QOS options */
+int priority = 0;		/* skb->priority */
 int icmp_sock;			/* socket file descriptor */
 u_char outpack[0x10000];
 int maxpacket = sizeof(outpack);
@@ -92,6 +93,7 @@
 static u_short in_cksum(const u_short *addr, int len, u_short salt);
 static void pr_icmph(__u8 type, __u8 code, __u32 info, struct icmphdr *icp);
 static int parsetos(char *str);
+static int parsepriority(const char *str);
 
 static struct {
 	struct cmsghdr cm;
@@ -124,7 +126,7 @@
 	source.sin_family = AF_INET;
 
 	preload = 1;
-	while ((ch = getopt(argc, argv, COMMON_OPTSTR "bRT:")) != EOF) {
+	while ((ch = getopt(argc, argv, COMMON_OPTSTR "bRT:P:")) != EOF) {
 		switch(ch) {
 		case 'b':
 		        broadcast_pings = 1;
@@ -138,6 +140,15 @@
 				exit(2);
 			}
 			break;
+		case 'P':
+			priority = parsepriority(optarg);
+			if (priority &&
+			    (setsockopt(icmp_sock, SOL_SOCKET, SO_PRIORITY,
+					(char *)&priority, sizeof(int)) < 0)) {
+				perror("ping: error setting priority");
+				exit(2);
+			}
+			break;
 		case 'R':
 			if (options & F_TIMESTAMP) {
 				fprintf(stderr, "Only one of -T or -R may be used\n");
@@ -1158,6 +1169,18 @@
 	return(tos);
 }
 
+#include <linux/pkt_sched.h>
+
+int parsepriority(const char *str)
+{
+	char *sep;
+	
+	if ((sep = strstr(str, ":")) == NULL)
+		return atoi(str);
+	*sep = '\0';
+	return TC_H_MAKE(atoi(str) << 16, atoi(sep + 1));
+}
+	
 #include <linux/filter.h>
 
 void install_filter(void)
@@ -1196,6 +1219,6 @@
 "Usage: ping [-LRUbdfnqrvVaA] [-c count] [-i interval] [-w deadline]\n"
 "            [-p pattern] [-s packetsize] [-t ttl] [-I interface or address]\n"
 "            [-M mtu discovery hint] [-S sndbuf]\n"
-"            [ -T timestamp option ] [ -Q tos ] [hop1 ...] destination\n");
+"            [ -T timestamp option ] [ -Q tos ] [ -P classid ] [hop1 ...] destination\n");
 	exit(2);
 }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-04-18 15:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-04-18 15:25 [LARTC] set skb->priority with ping Patrick McHardy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox