Export to GitHub

exports - CodeImplementation.wiki


Introduction

I do a some experiments in IPFW to understand a bit better the implementations around QoS methods.

Code

Added an options within ipfw2.c to do a better supporting to setting an IP PRECEDENCE in ToS fields.

NOTE: I worked only in ipfw2.c, the rest ongoing in this weekend. 1 Index: ipfw2.c 2 =================================================================== 3 RCS file: /home/ncvs/src/sbin/ipfw/ipfw2.c,v 4 retrieving revision 1.116 5 diff -u -r1.116 ipfw2.c 6 --- ipfw2.c 21 Feb 2008 22:55:54 -0000 1.116 7 +++ ipfw2.c 23 Feb 2008 01:36:12 -0000 8 @@ -177,6 +177,22 @@ 9 { NULL, 0 } 10 }; 11 12 +/* ToS PRECEDENCE fields. */ 13 + 14 +static struct _s_x f_iptospre[] = { 15 + { "netcontrol", IPTOS_NETCONTROL}, /* 0xe0 = 111 */ 16 + { "intercontrol", IPTOS_INTERCONTROL},/* 0xc0 = 110 */ 17 + { "criticecp", IPTOS_CRITICECP}, /* 0xa0 = 101 */ 18 + { "flashover", IPTOS_FLASHOVER}, /* 0x80 = 100 */ 19 + { "flash", IPTOS_FLASH}, /* 0x60 = 011 */ 20 + { "immediate", IPTOS_IMMEDIATE}, /* 0x40 = 010 */ 21 + { "priority", IPTOS_PRIORITY}, /* 0x20 = 001 */ 22 + { "routine", IPTOS_ROUTINE}, /* 0x00 = 000 */ 23 + { NULL, 0 } 24 +}; 25 + 26 +/* end, ToS PRECEDENCE fields. */ 27 + 28 static struct _s_x f_iptos[] = { 29 { "lowdelay", IPTOS_LOWDELAY}, 30 { "throughput", IPTOS_THROUGHPUT}, 31 @@ -283,6 +299,7 @@ 32 TOK_IPID, 33 TOK_IPPRECEDENCE, 34 TOK_IPTOS, 35 + TOK_IPTOSPRE, /* IP ToS PRECEDENCE */ 36 TOK_IPTTL, 37 TOK_IPVER, 38 TOK_ESTAB, 39 @@ -448,6 +465,7 @@ 40 { "iplen", TOK_IPLEN }, 41 { "ipid", TOK_IPID }, 42 { "ipprecedence", TOK_IPPRECEDENCE }, 43 + { "iptospre", TOK_IPTOSPRE }, /* IP ToS PRECEDENCE */ 44 { "iptos", TOK_IPTOS }, 45 { "ipttl", TOK_IPTTL }, 46 { "ipversion", TOK_IPVER }, 47 @@ -1524,6 +1542,13 @@ 48 for (l = rule->cmd_len - rule->act_ofs, cmd = ACTION_PTR(rule); 49 l > 0 ; l -= F_LEN(cmd), cmd += F_LEN(cmd)) { 50 switch(cmd->opcode) { 51 + 52 + /* Option to access IP PRECEDENCE. */ 53 + case O_IPTOSPRE: 54 + printf("iptospre %s", match_value(f_iptospre, cmd->arg1)); 55 + break; 56 + /* end. Option to access IP PRECEDENCE. */ 57 + 58 case O_CHECK_STATE: 59 printf("check-state"); 60 flags = HAVE_IP; /* avoid printing anything else */ 61 @@ -1902,6 +1927,15 @@ 62 print_flags("iptos", cmd, f_iptos); 63 break; 64 65 + /* IP PRECEDENCE Setting. */ 66 + 67 + case O_IPTOSPRE: 68 + print_flags("iptospre %s", match_value(f_iptospre, 69 + cmd->arg1)); 70 + break; 71 + 72 + /* ends. IP PRECEDENCE Setting. */ 73 + 74 case O_ICMPTYPE: 75 print_icmptypes((ipfw_insn_u32 *)cmd); 76 break; 77 @@ -2712,7 +2746,10 @@ 78 "RULE-BODY: check-state [PARAMS] | ACTION [PARAMS] ADDR [OPTION_LIST]\n" 79 "ACTION: check-state | allow | count | deny | unreach{,6} CODE |\n" 80 " skipto N | {divert|tee} PORT | forward ADDR |\n" 81 -" pipe N | queue N | nat N\n" 82 + 83 +/* Entry of ToS PRECEDENCE field */ 84 + 85 +" pipe N | queue N | nat N | iptospre CODE\n" 86 "PARAMS: [log [logamount LOGLIMIT]] [altq QUEUE_NAME]\n" 87 "ADDR: [ MAC dst src ether_type ] \n" 88 " [ ip from IPADDR [ PORT ] to IPADDR [ PORTLIST ] ]\n" 89 @@ -2723,7 +2760,10 @@ 90 "IPLIST: { ip | ip/bits | ip:mask }[,IPLIST]\n" 91 "OPTION_LIST: OPTION [OPTION_LIST]\n" 92 "OPTION: bridged | diverted | diverted-loopback | diverted-output |\n" 93 -" {dst-ip|src-ip} IPADDR | {dst-ip6|src-ip6|dst-ipv6|src-ipv6} IP6ADDR |\n" 94 +/* Add entry about IP PRECEDENCE */ 95 +" iptospre CODE | {dst-ip|src-ip} IPADDR |\n" 96 +/* Add entry about IP PRECEDENCE */ 97 +" {dst-ip6|src-ip6|dst-ipv6|src-ipv6} IP6ADDR |\n" 98 " {dst-port|src-port} LIST |\n" 99 " estab | frag | {gid|uid} N | icmptypes LIST | in | out | ipid LIST |\n" 100 " iplen LIST | ipoptions SPEC | ipprecedence | ipsec | iptos SPEC |\n" 101 @@ -4848,6 +4888,22 @@ 102 action->opcode = O_COUNT; 103 break; 104 105 + /* 106 + * Add suport ToS PRECEDENCE. 107 + */ 108 + 109 + /* Less ip_fw.h, see it man */ 110 + 111 + /* Setting ToS PRECEDENCE fields. */ 112 + 113 + case TOK_IPTOSPRE: 114 + NEED1("need iptospre arg\n"); 115 + fill_flags(action, O_IPTOSPRE, f_iptospre, *av); 116 + ac--; av++; 117 + break; 118 + 119 + /* ends. Setting ToS PRECEDENCE fields. */ 120 + 121 case TOK_QUEUE: 122 action->opcode = O_QUEUE; 123 goto chkarg; 124 @@ -5344,6 +5400,14 @@ 125 ac--; av++; 126 break; 127 128 + /* Entry ToS IP PRECEDENCE. */ 129 + case TOK_IPTOSPRE: 130 + NEED1("missing argument for iptospre"); 131 + fill_flags(cmd, O_IPTOSPRE, f_iptospre, *av); 132 + ac--; av++; 133 + break; 134 + /* ends. Entry ToS IP PRECEDENCE. */ 135 + 136 case TOK_UID: 137 NEED1("uid requires argument"); 138 {