Hottest Free Downloads - DownloadPipe.com Over 197,000 downloads! Bookmark Now!
DownloadPipe.com - New Downloads Every Minute
 SEARCH:
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

per packet QoS (DSCP)

 
   Linux (Home) -> Networking RSS
Next:  Hardware for FC8  
Author Message
aapocketz

External


Since: Dec 08, 2008
Posts: 1



(Msg. 1) Posted: Mon Dec 08, 2008 12:52 pm
Post subject: per packet QoS (DSCP)
Archived from groups: comp>os>linux>networking (more info?)

My application calls for sending different UDP packets with different
QoS priority, using DSCP. To do this I wanted to modify the ToS byte
in the IP header (bits 8-15 of the IPv4 header) on a per packet
basis.

It appears that this is possible using "ancillary data" and sendmsg/
recvmsg() API and the cmsg routines (http://manpages.ubuntu.com/
manpages/intrepid/man3/cmsg.html) to modify the header fields.

I cannot get this to work. Can anyone provide an example that does?
I am using ubuntu 8.10 and I have tried several things. Here is a
current little test client. Looking at wireshark I do not see any
changes to the TOS field (stays zero no matter what). I even tried
changing things like TTL field without any luck either. Any ideas?

#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string>
#include <string.h>


#define BUFLEN 512
#define NPACK 10
#define PORT 9930

void diep(const char *s) {
perror(s);
exit(1);
}


#define SRV_IP "127.0.0.1"
/* diep(), #includes and #defines like in the server */

int main(void) {
sockaddr_in si_other = {0};
msghdr msg = {0};
int s, i;
char buf[BUFLEN];

if ((s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
diep("socket");

si_other.sin_family = AF_INET;
si_other.sin_port = htons(PORT);
if (inet_aton(SRV_IP, &si_other.sin_addr) == 0) {
fprintf(stderr, "inet_aton() failed\n");
exit(1);
}

for (i = 0; i < NPACK; i++) {
printf("Sending packet %d\n", i);
sprintf(buf, "This is packet %d\n", i);
//if (sendto(s, buf, BUFLEN, 0, (sockaddr *)&si_other, slen) == -1)
// diep("sendto()");

// sets the address to send to
msg.msg_name = &si_other;
msg.msg_namelen = sizeof(si_other);

iovec iov[1];
msg.msg_iov = iov ;
msg.msg_iovlen = 1;
int test = 0xEFBEADDE;

iov[0].iov_base = &test;
iov[0].iov_len = sizeof test;


// sets the control ancillary data
cmsghdr * cmsg;
//int tos = 0xBEBAFECA; // set to low delay
int tos = 6; // set to low delay

char buf[CMSG_SPACE(sizeof(tos))];
msg.msg_control = buf;
msg.msg_controllen = sizeof(buf);

cmsg = CMSG_FIRSTHDR(&msg); // set to first header
if(cmsg == NULL)
{
fprintf(stderr, "CMSG_FIRSTHDR FAILED");
exit(1);
}
// first header is the TOS header
cmsg->cmsg_level = IPPROTO_IP;
cmsg->cmsg_type = IP_TOS;
cmsg->cmsg_len = CMSG_LEN(sizeof(tos));
*((int *) CMSG_DATA(cmsg)) = tos;
//void * data = CMSG_DATA(cmsg); // set the data
//memcpy(data, (void*) &tos, sizeof(tos));
msg.msg_controllen = cmsg->cmsg_len;

if (sendmsg(s, &msg, 0) < 0)
diep("sendmsg()");
}

close(s);
return 0;
}
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Per-packet IP DSCP/TOS Marking - It is interesting to know whether there is a way to conditionally mark *each* outgoing IP packet with a *different* DSCP/TOS marking? Basically: If I have a TCP socket which is used by 2 different applications, each of which generates a particular kind....

How to Distinguish between a reset packet and a normal pac.. - How Distinguish between a Reset Packet and a normal Data or Ack or Request packet.

DSCP & Default Linux routing - Hi all, I'd appreciate if someone can clarify this for me. From the source code (ip_forward.c), it seems that skb->priority is set from the "TOS bits" (mask 0x1E) in the TOS byte. Assume that an end point application sets the value 0x...

Packet forwarding - Is there something similar to the FreeBSD ipfw 'fwd' command in iptables? I'm trying to split traffic from a LAN across 3 public IPs for load balancing purposes. Thanks -- Andy Zhang

Packet forwarding - hi, I want to know if there is any program which can be run with user privileges on linux which can listen to a port and forward all packets arriving at that port to a destination machine. Lets say i have 3 computers. X,Y,Z X can connect to Y and Y can....
       Linux (Home) -> Networking All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Categories:
 Windows Forums
 Game Forums
  Linux Forums
 Mac Forums
 PDA Forums
 Mobile Forums
  Top  |  Store  |  RSS Feeds RSS  |  Data Feeds  |  Advertise  |  Submit  |  Bookmark  |  Newsletter  |  Contact