├── bridge ├── .gitignore ├── Makefile └── br_common.h ├── genl ├── .gitignore ├── static-syms.c ├── genl_utils.h └── Makefile ├── ip ├── .gitignore ├── rtpr ├── routef ├── static-syms.c ├── tunnel.h ├── routel ├── Makefile ├── link_veth.c ├── iplink_macvtap.c ├── iplink_macvlan.c └── rtm_map.c ├── man ├── man8 │ ├── nstat.8 │ ├── ctstat.8 │ ├── routef.8 │ ├── rtstat.8 │ ├── tc-pfifo.8 │ ├── ss.8 │ ├── .gitignore │ ├── ip-netconf.8 │ ├── routel.8 │ ├── Makefile │ ├── rtacct.8 │ ├── ip-maddress.8 │ ├── ip-mroute.8 │ ├── ip-addrlabel.8 │ ├── tc-pfifo_fast.8 │ ├── tc-choke.8 │ ├── ip-monitor.8 │ ├── rtmon.8 │ ├── ip-ntable.8 │ ├── tc-hfsc.8 │ ├── lnstat.8 │ ├── tc-bfifo.8 │ └── tc-drr.8 ├── man7 │ └── Makefile ├── man3 │ └── Makefile └── Makefile ├── doc ├── SNAPSHOT.tex ├── do-psnup ├── Plan ├── preamble.tex ├── rtstat.sgml ├── Makefile └── actions │ └── gact-usage ├── etc └── iproute2 │ ├── group │ ├── ematch_map │ ├── rt_tables │ ├── rt_scopes │ ├── rt_realms │ ├── rt_protos │ └── rt_dsfield ├── include ├── SNAPSHOT.h ├── linux │ ├── veth.h │ ├── tc_ematch │ │ ├── tc_em_nbyte.h │ │ ├── tc_em_text.h │ │ ├── tc_em_cmp.h │ │ └── tc_em_meta.h │ ├── tc_act │ │ ├── tc_ipt.h │ │ ├── tc_nat.h │ │ ├── tc_csum.h │ │ ├── tc_gact.h │ │ ├── tc_pedit.h │ │ ├── tc_mirred.h │ │ └── tc_skbedit.h │ ├── netconf.h │ ├── sock_diag.h │ ├── if_addrlabel.h │ ├── socket.h │ ├── atmapi.h │ ├── unix_diag.h │ ├── netfilter │ │ └── xt_tcpudp.h │ ├── tcp_metrics.h │ ├── gen_stats.h │ ├── types.h │ ├── if_addr.h │ ├── netdevice.h │ ├── atmioc.h │ ├── netfilter.h │ ├── fib_rules.h │ ├── ip6_tunnel.h │ ├── if_vlan.h │ ├── genetlink.h │ ├── netfilter_ipv4.h │ ├── hdlc │ │ └── ioctl.h │ └── if_tunnel.h ├── rtm_map.h ├── ll_map.h ├── libgenl.h ├── libiptc │ └── ipt_kernel_headers.h ├── dlfcn.h ├── rt_names.h ├── iptables_common.h └── xt-internal.h ├── tc ├── .gitignore ├── tc_cbq.h ├── tc_red.h ├── static-syms.c ├── p_tcp.c ├── p_udp.c ├── tc_core.h ├── tc_common.h ├── tc_estimator.c ├── p_icmp.c ├── README.last ├── q_ingress.c ├── tc_cbq.c ├── emp_ematch.y ├── m_estimator.c ├── tc_red.c ├── m_pedit.h ├── q_multiq.c ├── m_ematch.h ├── q_fifo.c ├── tc_monitor.c ├── q_drr.c └── f_cgroup.c ├── netem ├── .gitignore ├── Makefile ├── pareto.c ├── normal.c ├── stats.c └── paretonormal.c ├── misc ├── .gitignore ├── ssfilter.h ├── Makefile └── lnstat.h ├── .gitignore ├── lib ├── Makefile ├── ipx_ntop.c ├── dnet_pton.c ├── inet_proto.c ├── libgenl.c ├── ipx_pton.c ├── dnet_ntop.c ├── ll_addr.c ├── ll_proto.c └── ll_types.c ├── testsuite ├── tests │ ├── cbq.t │ ├── dsmark.t │ ├── policer │ └── cls-testbed.t ├── iproute2 │ └── Makefile ├── Makefile └── lib │ └── generic.sh ├── README.devel ├── examples ├── diffserv │ ├── ef-prio │ ├── efcbq │ ├── Edge1 │ └── README ├── SYN-DoS.rate.limit ├── gaiconf └── cbqinit.eth1 ├── README.decnet ├── README ├── Makefile └── README.lnstat /bridge/.gitignore: -------------------------------------------------------------------------------- 1 | bridge 2 | -------------------------------------------------------------------------------- /genl/.gitignore: -------------------------------------------------------------------------------- 1 | genl 2 | -------------------------------------------------------------------------------- /ip/.gitignore: -------------------------------------------------------------------------------- 1 | ip 2 | rtmon 3 | -------------------------------------------------------------------------------- /man/man8/nstat.8: -------------------------------------------------------------------------------- 1 | .so man8/rtacct.8 2 | -------------------------------------------------------------------------------- /doc/SNAPSHOT.tex: -------------------------------------------------------------------------------- 1 | \def\Draft{020116} 2 | -------------------------------------------------------------------------------- /man/man8/ctstat.8: -------------------------------------------------------------------------------- 1 | .so man8/lnstat.8 2 | -------------------------------------------------------------------------------- /man/man8/routef.8: -------------------------------------------------------------------------------- 1 | .so man8/routel.8 2 | -------------------------------------------------------------------------------- /man/man8/rtstat.8: -------------------------------------------------------------------------------- 1 | .so man8/lnstat.8 2 | -------------------------------------------------------------------------------- /man/man8/tc-pfifo.8: -------------------------------------------------------------------------------- 1 | .so man8/tc-bfifo.8 2 | -------------------------------------------------------------------------------- /etc/iproute2/group: -------------------------------------------------------------------------------- 1 | # device group names 2 | 0 default 3 | -------------------------------------------------------------------------------- /include/SNAPSHOT.h: -------------------------------------------------------------------------------- 1 | static const char SNAPSHOT[] = "130221"; 2 | -------------------------------------------------------------------------------- /ip/rtpr: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | exec tr "[\\\\]" "[ 4 | ]" 5 | -------------------------------------------------------------------------------- /tc/.gitignore: -------------------------------------------------------------------------------- 1 | *.yacc.c 2 | *.lex.c 3 | *.output 4 | *.yacc.h 5 | tc 6 | -------------------------------------------------------------------------------- /netem/.gitignore: -------------------------------------------------------------------------------- 1 | *.dist 2 | maketable 3 | normal 4 | pareto 5 | paretonormal 6 | -------------------------------------------------------------------------------- /man/man8/ss.8: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sivasankariit/iproute2/HEAD/man/man8/ss.8 -------------------------------------------------------------------------------- /misc/.gitignore: -------------------------------------------------------------------------------- 1 | arpd 2 | ifstat 3 | ss 4 | ssfilter.c 5 | nstat 6 | lnstat 7 | rtacct 8 | -------------------------------------------------------------------------------- /man/man8/.gitignore: -------------------------------------------------------------------------------- 1 | # these pages are built 2 | ip-address.8 3 | ip-link.8 4 | ip-route.8 5 | 6 | -------------------------------------------------------------------------------- /etc/iproute2/ematch_map: -------------------------------------------------------------------------------- 1 | # lookup table for ematch kinds 2 | 1 cmp 3 | 2 nbyte 4 | 3 u32 5 | 4 meta 6 | 7 canid 7 | 8 ipset 8 | -------------------------------------------------------------------------------- /etc/iproute2/rt_tables: -------------------------------------------------------------------------------- 1 | # 2 | # reserved values 3 | # 4 | 255 local 5 | 254 main 6 | 253 default 7 | 0 unspec 8 | # 9 | # local 10 | # 11 | #1 inr.ruhep 12 | -------------------------------------------------------------------------------- /etc/iproute2/rt_scopes: -------------------------------------------------------------------------------- 1 | # 2 | # reserved values 3 | # 4 | 0 global 5 | 255 nowhere 6 | 254 host 7 | 253 link 8 | # 9 | # pseudo-reserved 10 | # 11 | 200 site 12 | -------------------------------------------------------------------------------- /etc/iproute2/rt_realms: -------------------------------------------------------------------------------- 1 | # 2 | # reserved values 3 | # 4 | 0 cosmos 5 | # 6 | # local 7 | # 8 | #1 inr.ac 9 | #2 inr.ruhep 10 | #3 freenet 11 | #4 radio-msu 12 | #5 russia 13 | #6 internet 14 | -------------------------------------------------------------------------------- /ip/routef: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | if [ -z "$*" ] ; then 4 | exec ip -4 ro flush scope global type unicast 5 | else 6 | echo "Usage: routef" 7 | echo 8 | echo "This script will flush the IPv4 routing table" 9 | fi 10 | -------------------------------------------------------------------------------- /include/linux/veth.h: -------------------------------------------------------------------------------- 1 | #ifndef __NET_VETH_H_ 2 | #define __NET_VETH_H_ 3 | 4 | enum { 5 | VETH_INFO_UNSPEC, 6 | VETH_INFO_PEER, 7 | 8 | __VETH_INFO_MAX 9 | #define VETH_INFO_MAX (__VETH_INFO_MAX - 1) 10 | }; 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /man/man7/Makefile: -------------------------------------------------------------------------------- 1 | MAN7PAGES = tc-hfsc.7 2 | 3 | all: 4 | 5 | distclean: clean 6 | 7 | clean: 8 | 9 | install: 10 | $(INSTALLDIR) $(DESTDIR)$(MANDIR)/man7 11 | $(INSTALLMAN) $(MAN7PAGES) $(DESTDIR)$(MANDIR)/man7 12 | 13 | .PHONY: install clean distclean 14 | -------------------------------------------------------------------------------- /man/man3/Makefile: -------------------------------------------------------------------------------- 1 | MAN3PAGES=libnetlink.3 2 | 3 | all: 4 | 5 | distclean: clean 6 | 7 | clean: 8 | 9 | install: 10 | $(INSTALLDIR) $(DESTDIR)$(MANDIR)/man3 11 | $(INSTALLMAN) $(MAN3PAGES) $(DESTDIR)$(MANDIR)/man3 12 | 13 | .PHONY: install clean distclean 14 | -------------------------------------------------------------------------------- /include/rtm_map.h: -------------------------------------------------------------------------------- 1 | #ifndef __RTM_MAP_H__ 2 | #define __RTM_MAP_H__ 1 3 | 4 | char *rtnl_rtntype_n2a(int id, char *buf, int len); 5 | int rtnl_rtntype_a2n(int *id, char *arg); 6 | 7 | int get_rt_realms(__u32 *realms, char *arg); 8 | 9 | 10 | #endif /* __RTM_MAP_H__ */ 11 | -------------------------------------------------------------------------------- /bridge/Makefile: -------------------------------------------------------------------------------- 1 | BROBJ = bridge.o fdb.o monitor.o link.o mdb.o vlan.o 2 | 3 | include ../Config 4 | 5 | all: bridge 6 | 7 | bridge: $(BROBJ) $(LIBNETLINK) 8 | 9 | install: all 10 | install -m 0755 bridge $(DESTDIR)$(SBINDIR) 11 | 12 | clean: 13 | rm -f $(BROBJ) bridge 14 | 15 | -------------------------------------------------------------------------------- /include/linux/tc_ematch/tc_em_nbyte.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_EM_NBYTE_H 2 | #define __LINUX_TC_EM_NBYTE_H 3 | 4 | #include 5 | #include 6 | 7 | struct tcf_em_nbyte { 8 | __u16 off; 9 | __u16 len:12; 10 | __u8 layer:4; 11 | }; 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /tc/tc_cbq.h: -------------------------------------------------------------------------------- 1 | #ifndef _TC_CBQ_H_ 2 | #define _TC_CBQ_H_ 1 3 | 4 | unsigned tc_cbq_calc_maxidle(__u64 bndw, __u64 rate, unsigned avpkt, 5 | int ewma_log, unsigned maxburst); 6 | unsigned tc_cbq_calc_offtime(__u64 bndw, __u64 rate, unsigned avpkt, 7 | int ewma_log, unsigned minburst); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /tc/tc_red.h: -------------------------------------------------------------------------------- 1 | #ifndef _TC_RED_H_ 2 | #define _TC_RED_H_ 1 3 | 4 | extern int tc_red_eval_P(unsigned qmin, unsigned qmax, double prob); 5 | extern int tc_red_eval_ewma(unsigned qmin, unsigned burst, unsigned avpkt); 6 | extern int tc_red_eval_idle_damping(int wlog, unsigned avpkt, __u64 bandwidth, __u8 *sbuf); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /genl/static-syms.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file creates a dummy version of dynamic loading 3 | * for environments where dynamic linking 4 | * is not used or available. 5 | */ 6 | 7 | #include 8 | #include "dlfcn.h" 9 | 10 | void *_dlsym(const char *sym) 11 | { 12 | #include "static-syms.h" 13 | return NULL; 14 | } 15 | -------------------------------------------------------------------------------- /ip/static-syms.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file creates a dummy version of dynamic loading 3 | * for environments where dynamic linking 4 | * is not used or available. 5 | */ 6 | 7 | #include 8 | #include "dlfcn.h" 9 | 10 | void *_dlsym(const char *sym) 11 | { 12 | #include "static-syms.h" 13 | return NULL; 14 | } 15 | -------------------------------------------------------------------------------- /tc/static-syms.c: -------------------------------------------------------------------------------- 1 | /* 2 | * This file creates a dummy version of dynamic loading 3 | * for environments where dynamic linking 4 | * is not used or available. 5 | */ 6 | 7 | #include 8 | #include "dlfcn.h" 9 | 10 | void *_dlsym(const char *sym) 11 | { 12 | #include "static-syms.h" 13 | return NULL; 14 | } 15 | -------------------------------------------------------------------------------- /man/Makefile: -------------------------------------------------------------------------------- 1 | INSTALL=install 2 | INSTALLDIR=install -m 0755 -d 3 | INSTALLMAN=install -m 0644 4 | 5 | SUBDIRS = man3 man7 man8 6 | 7 | all clean install: 8 | @for subdir in $(SUBDIRS); do $(MAKE) -C $$subdir $@ || exit $$?; done 9 | 10 | distclean: clean 11 | 12 | .PHONY: install clean distclean 13 | 14 | .EXPORT_ALL_VARIABLES: 15 | -------------------------------------------------------------------------------- /include/linux/tc_ematch/tc_em_text.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_EM_TEXT_H 2 | #define __LINUX_TC_EM_TEXT_H 3 | 4 | #include 5 | #include 6 | 7 | #define TC_EM_TEXT_ALGOSIZ 16 8 | 9 | struct tcf_em_text { 10 | char algo[TC_EM_TEXT_ALGOSIZ]; 11 | __u16 from_offset; 12 | __u16 to_offset; 13 | __u16 pattern_len; 14 | __u8 from_layer:4; 15 | __u8 to_layer:4; 16 | __u8 pad; 17 | }; 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | static-syms.h 2 | config.* 3 | Config 4 | *.o 5 | *.a 6 | *.so 7 | *~ 8 | \#*# 9 | 10 | # cscope 11 | cscope.* 12 | ncscope.* 13 | TAGS 14 | 15 | # git files that we don't want to ignore even it they are dot-files 16 | !.gitignore 17 | !.mailmap 18 | 19 | # for patch generation 20 | *.diff 21 | *.patch 22 | *.orig 23 | *.rej 24 | 25 | # for quilt 26 | .pc 27 | patches 28 | series 29 | 30 | # for gdb 31 | .gdbinit 32 | .gdb_history 33 | *.gdb 34 | -------------------------------------------------------------------------------- /doc/do-psnup: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | # $1 = Temporary file . "string" 3 | # $2 = File to process . "string" 4 | # $3 = Page size . ie: a4 , letter ... "string" 5 | # $4 = Number of pages to fit on a single sheet . "numeric" 6 | 7 | if type psnup >&/dev/null; then 8 | echo "psnup -$4 -p$3 $1 $2" 9 | psnup -$4 -p$3 $1 $2 10 | elif type psmulti >&/dev/null; then 11 | echo "psmulti $1 > $2" 12 | psmulti $1 > $2 13 | else 14 | echo "cp $1 $2" 15 | cp $1 $2 16 | fi 17 | -------------------------------------------------------------------------------- /genl/genl_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef _TC_UTIL_H_ 2 | #define _TC_UTIL_H_ 1 3 | 4 | #include "utils.h" 5 | #include "linux/genetlink.h" 6 | 7 | struct genl_util 8 | { 9 | struct genl_util *next; 10 | char name[16]; 11 | int (*parse_genlopt)(struct genl_util *fu, int argc, char **argv); 12 | int (*print_genlopt)(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); 13 | }; 14 | 15 | extern int genl_ctrl_resolve_family(const char *family); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /lib/Makefile: -------------------------------------------------------------------------------- 1 | include ../Config 2 | 3 | CFLAGS += -fPIC 4 | 5 | UTILOBJ=utils.o rt_names.o ll_types.o ll_proto.o ll_addr.o inet_proto.o 6 | 7 | NLOBJ=libgenl.o ll_map.o libnetlink.o 8 | 9 | all: libnetlink.a libutil.a 10 | 11 | libnetlink.a: $(NLOBJ) 12 | $(AR) rcs $@ $(NLOBJ) 13 | 14 | libutil.a: $(UTILOBJ) $(ADDLIB) 15 | $(AR) rcs $@ $(UTILOBJ) $(ADDLIB) 16 | 17 | install: 18 | 19 | clean: 20 | rm -f $(NLOBJ) $(UTILOBJ) $(ADDLIB) libnetlink.a libutil.a 21 | 22 | -------------------------------------------------------------------------------- /etc/iproute2/rt_protos: -------------------------------------------------------------------------------- 1 | # 2 | # Reserved protocols. 3 | # 4 | 0 unspec 5 | 1 redirect 6 | 2 kernel 7 | 3 boot 8 | 4 static 9 | 8 gated 10 | 9 ra 11 | 10 mrt 12 | 11 zebra 13 | 12 bird 14 | 13 dnrouted 15 | 14 xorp 16 | 15 ntk 17 | 16 dhcp 18 | 19 | # 20 | # Used by me for gated 21 | # 22 | 254 gated/aggr 23 | 253 gated/bgp 24 | 252 gated/ospf 25 | 251 gated/ospfase 26 | 250 gated/rip 27 | 249 gated/static 28 | 248 gated/conn 29 | 247 gated/inet 30 | 246 gated/default 31 | -------------------------------------------------------------------------------- /include/linux/tc_act/tc_ipt.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_IPT_H 2 | #define __LINUX_TC_IPT_H 3 | 4 | #include 5 | 6 | #define TCA_ACT_IPT 6 7 | 8 | enum { 9 | TCA_IPT_UNSPEC, 10 | TCA_IPT_TABLE, 11 | TCA_IPT_HOOK, 12 | TCA_IPT_INDEX, 13 | TCA_IPT_CNT, 14 | TCA_IPT_TM, 15 | TCA_IPT_TARG, 16 | __TCA_IPT_MAX 17 | }; 18 | #define TCA_IPT_MAX (__TCA_IPT_MAX - 1) 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /misc/ssfilter.h: -------------------------------------------------------------------------------- 1 | #define SSF_DCOND 0 2 | #define SSF_SCOND 1 3 | #define SSF_OR 2 4 | #define SSF_AND 3 5 | #define SSF_NOT 4 6 | #define SSF_D_GE 5 7 | #define SSF_D_LE 6 8 | #define SSF_S_GE 7 9 | #define SSF_S_LE 8 10 | #define SSF_S_AUTO 9 11 | 12 | struct ssfilter 13 | { 14 | int type; 15 | struct ssfilter *post; 16 | struct ssfilter *pred; 17 | }; 18 | 19 | int ssfilter_parse(struct ssfilter **f, int argc, char **argv, FILE *fp); 20 | void *parse_hostcond(char*); 21 | 22 | -------------------------------------------------------------------------------- /include/linux/tc_ematch/tc_em_cmp.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_EM_CMP_H 2 | #define __LINUX_TC_EM_CMP_H 3 | 4 | #include 5 | #include 6 | 7 | struct tcf_em_cmp { 8 | __u32 val; 9 | __u32 mask; 10 | __u16 off; 11 | __u8 align:4; 12 | __u8 flags:4; 13 | __u8 layer:4; 14 | __u8 opnd:4; 15 | }; 16 | 17 | enum { 18 | TCF_EM_ALIGN_U8 = 1, 19 | TCF_EM_ALIGN_U16 = 2, 20 | TCF_EM_ALIGN_U32 = 4 21 | }; 22 | 23 | #define TCF_EM_CMP_TRANS 1 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /include/linux/tc_act/tc_nat.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_NAT_H 2 | #define __LINUX_TC_NAT_H 3 | 4 | #include 5 | #include 6 | 7 | #define TCA_ACT_NAT 9 8 | 9 | enum { 10 | TCA_NAT_UNSPEC, 11 | TCA_NAT_PARMS, 12 | TCA_NAT_TM, 13 | __TCA_NAT_MAX 14 | }; 15 | #define TCA_NAT_MAX (__TCA_NAT_MAX - 1) 16 | 17 | #define TCA_NAT_FLAG_EGRESS 1 18 | 19 | struct tc_nat { 20 | tc_gen; 21 | __be32 old_addr; 22 | __be32 new_addr; 23 | __be32 mask; 24 | __u32 flags; 25 | }; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /include/ll_map.h: -------------------------------------------------------------------------------- 1 | #ifndef __LL_MAP_H__ 2 | #define __LL_MAP_H__ 1 3 | 4 | extern int ll_remember_index(const struct sockaddr_nl *who, 5 | struct nlmsghdr *n, void *arg); 6 | extern int ll_init_map(struct rtnl_handle *rth); 7 | extern unsigned ll_name_to_index(const char *name); 8 | extern const char *ll_index_to_name(unsigned idx); 9 | extern const char *ll_idx_n2a(unsigned idx, char *buf); 10 | extern int ll_index_to_type(unsigned idx); 11 | extern unsigned ll_index_to_flags(unsigned idx); 12 | 13 | #endif /* __LL_MAP_H__ */ 14 | -------------------------------------------------------------------------------- /include/linux/netconf.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINUX_NETCONF_H_ 2 | #define _LINUX_NETCONF_H_ 3 | 4 | #include 5 | #include 6 | 7 | struct netconfmsg { 8 | __u8 ncm_family; 9 | }; 10 | 11 | enum { 12 | NETCONFA_UNSPEC, 13 | NETCONFA_IFINDEX, 14 | NETCONFA_FORWARDING, 15 | NETCONFA_RP_FILTER, 16 | NETCONFA_MC_FORWARDING, 17 | __NETCONFA_MAX 18 | }; 19 | #define NETCONFA_MAX (__NETCONFA_MAX - 1) 20 | 21 | #define NETCONFA_IFINDEX_ALL -1 22 | #define NETCONFA_IFINDEX_DEFAULT -2 23 | 24 | #endif /* _LINUX_NETCONF_H_ */ 25 | -------------------------------------------------------------------------------- /include/linux/sock_diag.h: -------------------------------------------------------------------------------- 1 | #ifndef __SOCK_DIAG_H__ 2 | #define __SOCK_DIAG_H__ 3 | 4 | #include 5 | 6 | #define SOCK_DIAG_BY_FAMILY 20 7 | 8 | struct sock_diag_req { 9 | __u8 sdiag_family; 10 | __u8 sdiag_protocol; 11 | }; 12 | 13 | enum { 14 | SK_MEMINFO_RMEM_ALLOC, 15 | SK_MEMINFO_RCVBUF, 16 | SK_MEMINFO_WMEM_ALLOC, 17 | SK_MEMINFO_SNDBUF, 18 | SK_MEMINFO_FWD_ALLOC, 19 | SK_MEMINFO_WMEM_QUEUED, 20 | SK_MEMINFO_OPTMEM, 21 | SK_MEMINFO_BACKLOG, 22 | 23 | SK_MEMINFO_VARS, 24 | }; 25 | 26 | #endif /* __SOCK_DIAG_H__ */ 27 | -------------------------------------------------------------------------------- /etc/iproute2/rt_dsfield: -------------------------------------------------------------------------------- 1 | 0x00 default 2 | 0x10 lowdelay 3 | 0x08 throughput 4 | 0x04 reliability 5 | # This value overlap with ECT, do not use it! 6 | 0x02 mincost 7 | # These values seems do not want to die, Cisco likes them by a strange reason. 8 | 0x20 priority 9 | 0x40 immediate 10 | 0x60 flash 11 | 0x80 flash-override 12 | 0xa0 critical 13 | 0xc0 internet 14 | 0xe0 network 15 | # Newer RFC2597 values 16 | 0x28 AF11 17 | 0x30 AF12 18 | 0x38 AF13 19 | 0x48 AF21 20 | 0x50 AF22 21 | 0x58 AF23 22 | 0x68 AF31 23 | 0x70 AF32 24 | 0x78 AF33 25 | 0x88 AF41 26 | 0x90 AF42 27 | 0x98 AF43 28 | -------------------------------------------------------------------------------- /doc/Plan: -------------------------------------------------------------------------------- 1 | Partially finished work. 2 | 3 | 1. User Reference manuals. 4 | 1.1 IP Command reference (ip-cref.tex, published) 5 | 1.2 TC Command reference (tc-cref.tex) 6 | 1.3 IP tunnels (ip-tunnels.tex, published) 7 | 8 | 2. Linux-2.2 Networking API 9 | 2.1 RTNETLINK (api-rtnl.tex) 10 | 2.2 Path MTU Discovery (api-pmtudisc.tex) 11 | 2.3 IPv6 Flow Labels (api-ip6-flowlabels.tex, published) 12 | 2.4 Miscellaneous extensions (api-misc.tex) 13 | 14 | 3. Linux-2.2 Networking Intra-Kernel Interfaces 15 | 3.1 NetDev --- Networking Devices and netdev... (iki-netdev.tex) 16 | 3.2 Neighbour cache and destination cache. (iki-neighdst.tex) 17 | -------------------------------------------------------------------------------- /testsuite/tests/cbq.t: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | $TC qdisc del dev $DEV root >/dev/null 2>&1 3 | $TC qdisc add dev $DEV root handle 10:0 cbq bandwidth 100Mbit avpkt 1400 mpu 64 4 | $TC class add dev $DEV parent 10:0 classid 10:12 cbq bandwidth 100mbit rate 100mbit allot 1514 prio 3 maxburst 1 avpkt 500 bounded 5 | $TC qdisc list dev $DEV 6 | $TC qdisc del dev $DEV root 7 | $TC qdisc list dev $DEV 8 | $TC qdisc add dev $DEV root handle 10:0 cbq bandwidth 100Mbit avpkt 1400 mpu 64 9 | $TC class add dev $DEV parent 10:0 classid 10:12 cbq bandwidth 100mbit rate 100mbit allot 1514 prio 3 maxburst 1 avpkt 500 bounded 10 | $TC qdisc del dev $DEV root 11 | -------------------------------------------------------------------------------- /README.devel: -------------------------------------------------------------------------------- 1 | Iproute2 development is closely tied to Linux kernel networking 2 | development. Most new features require a kernel and a utility component. 3 | 4 | Please submit both to the Linux networking mailing list 5 | 6 | 7 | The current source is in the git repository: 8 | git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git 9 | 10 | The master branch contains the source corresponding to the current 11 | code in the mainline Linux kernel (ie follows Linus). The net-next 12 | branch is a temporary branch that tracks the code intended for the 13 | next release; it corresponds with networking development branch in 14 | the kernel. 15 | 16 | -------------------------------------------------------------------------------- /bridge/br_common.h: -------------------------------------------------------------------------------- 1 | extern int print_linkinfo(const struct sockaddr_nl *who, 2 | struct nlmsghdr *n, 3 | void *arg); 4 | extern int print_fdb(const struct sockaddr_nl *who, 5 | struct nlmsghdr *n, void *arg); 6 | extern int print_mdb(const struct sockaddr_nl *who, 7 | struct nlmsghdr *n, void *arg); 8 | 9 | extern int do_fdb(int argc, char **argv); 10 | extern int do_mdb(int argc, char **argv); 11 | extern int do_monitor(int argc, char **argv); 12 | extern int do_vlan(int argc, char **argv); 13 | extern int do_link(int argc, char **argv); 14 | 15 | extern int preferred_family; 16 | extern int show_stats; 17 | extern int show_details; 18 | extern int timestamp; 19 | extern struct rtnl_handle rth; 20 | -------------------------------------------------------------------------------- /include/linux/tc_act/tc_csum.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_CSUM_H 2 | #define __LINUX_TC_CSUM_H 3 | 4 | #include 5 | #include 6 | 7 | #define TCA_ACT_CSUM 16 8 | 9 | enum { 10 | TCA_CSUM_UNSPEC, 11 | TCA_CSUM_PARMS, 12 | TCA_CSUM_TM, 13 | __TCA_CSUM_MAX 14 | }; 15 | #define TCA_CSUM_MAX (__TCA_CSUM_MAX - 1) 16 | 17 | enum { 18 | TCA_CSUM_UPDATE_FLAG_IPV4HDR = 1, 19 | TCA_CSUM_UPDATE_FLAG_ICMP = 2, 20 | TCA_CSUM_UPDATE_FLAG_IGMP = 4, 21 | TCA_CSUM_UPDATE_FLAG_TCP = 8, 22 | TCA_CSUM_UPDATE_FLAG_UDP = 16, 23 | TCA_CSUM_UPDATE_FLAG_UDPLITE = 32 24 | }; 25 | 26 | struct tc_csum { 27 | tc_gen; 28 | 29 | __u32 update_flags; 30 | }; 31 | 32 | #endif /* __LINUX_TC_CSUM_H */ 33 | -------------------------------------------------------------------------------- /include/linux/tc_act/tc_gact.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_GACT_H 2 | #define __LINUX_TC_GACT_H 3 | 4 | #include 5 | #include 6 | 7 | #define TCA_ACT_GACT 5 8 | struct tc_gact { 9 | tc_gen; 10 | 11 | }; 12 | 13 | struct tc_gact_p { 14 | #define PGACT_NONE 0 15 | #define PGACT_NETRAND 1 16 | #define PGACT_DETERM 2 17 | #define MAX_RAND (PGACT_DETERM + 1 ) 18 | __u16 ptype; 19 | __u16 pval; 20 | int paction; 21 | }; 22 | 23 | enum { 24 | TCA_GACT_UNSPEC, 25 | TCA_GACT_TM, 26 | TCA_GACT_PARMS, 27 | TCA_GACT_PROB, 28 | __TCA_GACT_MAX 29 | }; 30 | #define TCA_GACT_MAX (__TCA_GACT_MAX - 1) 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/libgenl.h: -------------------------------------------------------------------------------- 1 | #ifndef __LIBGENL_H__ 2 | #define __LIBGENL_H__ 3 | 4 | #include "libnetlink.h" 5 | 6 | #define GENL_REQUEST(_req, _bufsiz, _family, _hdrsiz, _ver, _cmd, _flags) \ 7 | struct { \ 8 | struct nlmsghdr n; \ 9 | struct genlmsghdr g; \ 10 | char buf[NLMSG_ALIGN(_hdrsiz) + (_bufsiz)]; \ 11 | } _req = { \ 12 | .n = { \ 13 | .nlmsg_type = (_family), \ 14 | .nlmsg_flags = (_flags), \ 15 | .nlmsg_len = NLMSG_LENGTH(GENL_HDRLEN + (_hdrsiz)), \ 16 | }, \ 17 | .g = { \ 18 | .cmd = (_cmd), \ 19 | .version = (_ver), \ 20 | }, \ 21 | } 22 | 23 | extern int genl_resolve_family(struct rtnl_handle *grth, const char *family); 24 | 25 | #endif /* __LIBGENL_H__ */ 26 | -------------------------------------------------------------------------------- /doc/preamble.tex: -------------------------------------------------------------------------------- 1 | \textwidth 6.0in 2 | \textheight 8.5in 3 | 4 | \input SNAPSHOT 5 | 6 | \pagestyle{myheadings} 7 | \markboth{\protect\TITLE}{} 8 | \markright{{\protect\sc iproute2-ss\Draft}} 9 | 10 | % To print it in compact form: both sides on one sheet (psnup -2) 11 | \evensidemargin=\oddsidemargin 12 | 13 | \newenvironment{NB}{\bgroup \vskip 1mm\leftskip 1cm \footnotesize \noindent NB. 14 | }{\par\egroup \vskip 1mm} 15 | 16 | \def\threeonly{[2.3.15+ only] } 17 | 18 | \begin{document} 19 | 20 | \makeatletter 21 | \renewcommand{\@oddhead}{{\protect\sc iproute2-ss\Draft} \hfill \protect\arabic{page}} 22 | \makeatother 23 | \let\oldthefootnote\thefootnote 24 | \def\thefootnote{} 25 | \footnotetext{Copyright \copyright~1999 A.N.Kuznetsov} 26 | 27 | -------------------------------------------------------------------------------- /netem/Makefile: -------------------------------------------------------------------------------- 1 | DISTGEN = maketable normal pareto paretonormal 2 | DISTDATA = normal.dist pareto.dist paretonormal.dist experimental.dist 3 | 4 | HOSTCC ?= $(CC) 5 | CCOPTS = $(CBUILD_CFLAGS) 6 | LDLIBS += -lm 7 | 8 | all: $(DISTGEN) $(DISTDATA) 9 | 10 | $(DISTGEN): 11 | $(HOSTCC) $(CCOPTS) -I../include -o $@ $@.c -lm 12 | 13 | %.dist: % 14 | ./$* > $@ 15 | 16 | experimental.dist: maketable experimental.dat 17 | ./maketable experimental.dat > experimental.dist 18 | 19 | stats: stats.c 20 | $(HOSTCC) $(CCOPTS) -I../include -o $@ $@.c -lm 21 | 22 | install: all 23 | mkdir -p $(DESTDIR)$(LIBDIR)/tc 24 | for i in $(DISTDATA); \ 25 | do install -m 644 $$i $(DESTDIR)$(LIBDIR)/tc; \ 26 | done 27 | 28 | clean: 29 | rm -f $(DISTDATA) $(DISTGEN) 30 | -------------------------------------------------------------------------------- /include/libiptc/ipt_kernel_headers.h: -------------------------------------------------------------------------------- 1 | /* This is the userspace/kernel interface for Generic IP Chains, 2 | required for libc6. */ 3 | #ifndef _FWCHAINS_KERNEL_HEADERS_H 4 | #define _FWCHAINS_KERNEL_HEADERS_H 5 | 6 | #include 7 | 8 | #if defined(__GLIBC__) && __GLIBC__ == 2 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #else /* libc5 */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #endif 26 | #endif 27 | -------------------------------------------------------------------------------- /include/linux/if_addrlabel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * if_addrlabel.h - netlink interface for address labels 3 | * 4 | * Copyright (C)2007 USAGI/WIDE Project, All Rights Reserved. 5 | * 6 | * Authors: 7 | * YOSHIFUJI Hideaki @ USAGI/WIDE 8 | */ 9 | 10 | #ifndef __LINUX_IF_ADDRLABEL_H 11 | #define __LINUX_IF_ADDRLABEL_H 12 | 13 | #include 14 | 15 | struct ifaddrlblmsg { 16 | __u8 ifal_family; /* Address family */ 17 | __u8 __ifal_reserved; /* Reserved */ 18 | __u8 ifal_prefixlen; /* Prefix length */ 19 | __u8 ifal_flags; /* Flags */ 20 | __u32 ifal_index; /* Link index */ 21 | __u32 ifal_seq; /* sequence number */ 22 | }; 23 | 24 | enum { 25 | IFAL_ADDRESS = 1, 26 | IFAL_LABEL = 2, 27 | __IFAL_MAX 28 | }; 29 | 30 | #define IFAL_MAX (__IFAL_MAX - 1) 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /include/linux/socket.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINUX_SOCKET_H 2 | #define _LINUX_SOCKET_H 3 | 4 | /* 5 | * Desired design of maximum size and alignment (see RFC2553) 6 | */ 7 | #define _K_SS_MAXSIZE 128 /* Implementation specific max size */ 8 | #define _K_SS_ALIGNSIZE (__alignof__ (struct sockaddr *)) 9 | /* Implementation specific desired alignment */ 10 | 11 | typedef unsigned short __kernel_sa_family_t; 12 | 13 | struct __kernel_sockaddr_storage { 14 | __kernel_sa_family_t ss_family; /* address family */ 15 | /* Following field(s) are implementation specific */ 16 | char __data[_K_SS_MAXSIZE - sizeof(unsigned short)]; 17 | /* space to achieve desired size, */ 18 | /* _SS_MAXSIZE value minus size of ss_family */ 19 | } __attribute__ ((aligned(_K_SS_ALIGNSIZE))); /* force desired alignment */ 20 | 21 | #endif /* _LINUX_SOCKET_H */ 22 | -------------------------------------------------------------------------------- /man/man8/ip-netconf.8: -------------------------------------------------------------------------------- 1 | .TH IP\-NETCONF 8 "13 Dec 2012" "iproute2" "Linux" 2 | .SH "NAME" 3 | ip-netconf \- network configuration monitoring 4 | .SH "SYNOPSIS" 5 | .sp 6 | .ad l 7 | .in +8 8 | .ti -8 9 | .BR "ip " " [ ip-OPTIONS ] " "netconf show" " [ " 10 | .B dev 11 | .IR NAME " ]" 12 | 13 | .SH DESCRIPTION 14 | The 15 | .B ip netconf 16 | utility can monitor IPv4 and IPv6 parameters (see 17 | .BR "/proc/sys/net/ipv[4|6]/conf/[all|DEV]/" ")" 18 | like forwarding, rp_filter 19 | or mc_forwarding status. 20 | 21 | If no interface is specified, the entry 22 | .B all 23 | is displayed. 24 | 25 | .SS ip netconf show - display network parameters 26 | 27 | .TP 28 | .BI dev " NAME" 29 | the name of the device to display network parameters for. 30 | 31 | .SH SEE ALSO 32 | .br 33 | .BR ip (8) 34 | 35 | .SH AUTHOR 36 | Original Manpage by Nicolas Dichtel 37 | -------------------------------------------------------------------------------- /testsuite/tests/dsmark.t: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # vim: ft=sh 3 | 4 | source lib/generic.sh 5 | 6 | ts_qdisc_available "dsmark" 7 | if [ $? -eq 0 ]; then 8 | ts_log "dsmark: Unsupported by $TC, skipping" 9 | exit 127 10 | fi 11 | 12 | ts_tc "dsmark" "dsmark root qdisc creation" \ 13 | qdisc add dev $DEV root handle 10:0 \ 14 | dsmark indices 64 default_index 1 set_tc_index 15 | 16 | ts_tc "dsmark" "dsmark class 1 creation" \ 17 | class change dev $DEV parent 10:0 classid 10:12 \ 18 | dsmark mask 0xff value 2 19 | 20 | ts_tc "dsmark" "dsmark class 2 creation" \ 21 | class change dev $DEV parent 10:0 classid 10:13 \ 22 | dsmark mask 0xfc value 4 23 | 24 | ts_tc "dsmark" "dsmark dump qdisc" \ 25 | qdisc list dev $DEV 26 | 27 | ts_tc "dsmark" "dsmark dump class" \ 28 | class list dev $DEV parent 10:0 29 | 30 | ts_tc "dsmark" "generic qdisc tree deletion" \ 31 | qdisc del dev $DEV root 32 | -------------------------------------------------------------------------------- /testsuite/iproute2/Makefile: -------------------------------------------------------------------------------- 1 | SUBDIRS := $(filter-out Makefile,$(wildcard *)) 2 | .PHONY: all configure clean distclean show $(SUBDIRS) 3 | 4 | all: configure 5 | @for dir in $(SUBDIRS); do \ 6 | echo "Entering $$dir" && cd $$dir && $(MAKE) && cd ..; \ 7 | done 8 | 9 | link: 10 | @if [ ! -L iproute2-this ]; then \ 11 | ln -s ../.. iproute2-this; \ 12 | fi 13 | 14 | configure: link 15 | @for dir in $(SUBDIRS); do \ 16 | echo "Entering $$dir" && cd $$dir && if [ -f configure ]; then ./configure; fi && cd ..; \ 17 | done 18 | 19 | clean: link 20 | @for dir in $(SUBDIRS); do \ 21 | echo "Entering $$dir" && cd $$dir && $(MAKE) clean && cd ..; \ 22 | done 23 | 24 | distclean: clean 25 | @for dir in $(SUBDIRS); do \ 26 | echo "Entering $$dir" && cd $$dir && $(MAKE) distclean && cd ..; \ 27 | done 28 | 29 | show: link 30 | @echo "$(SUBDIRS)" 31 | 32 | $(SUBDIRS): 33 | cd $@ && $(MAKE) 34 | -------------------------------------------------------------------------------- /include/dlfcn.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Stub dlfcn implementation for systems that lack shared library support 3 | * but obviously can still reference compiled-in symbols. 4 | */ 5 | 6 | #ifndef NO_SHARED_LIBS 7 | #include_next 8 | #else 9 | 10 | #define RTLD_LAZY 0 11 | #define RTLD_GLOBAL 1 12 | #define _FAKE_DLFCN_HDL (void *)0xbeefcafe 13 | 14 | static inline void *dlopen(const char *file, int flag) 15 | { 16 | if (file == NULL) 17 | return _FAKE_DLFCN_HDL; 18 | else 19 | return NULL; 20 | } 21 | 22 | extern void *_dlsym(const char *sym); 23 | static inline void *dlsym(void *handle, const char *sym) 24 | { 25 | if (handle != _FAKE_DLFCN_HDL) 26 | return NULL; 27 | return _dlsym(sym); 28 | } 29 | 30 | static inline char *dlerror(void) 31 | { 32 | return NULL; 33 | } 34 | 35 | static inline int dlclose(void *handle) 36 | { 37 | return (handle == _FAKE_DLFCN_HDL) ? 0 : 1; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /misc/Makefile: -------------------------------------------------------------------------------- 1 | SSOBJ=ss.o ssfilter.o 2 | LNSTATOBJ=lnstat.o lnstat_util.o 3 | 4 | TARGETS=ss nstat ifstat rtacct arpd lnstat 5 | 6 | include ../Config 7 | 8 | all: $(TARGETS) 9 | 10 | ss: $(SSOBJ) 11 | 12 | nstat: nstat.c 13 | $(CC) $(CFLAGS) $(LDFLAGS) -o nstat nstat.c -lm 14 | 15 | ifstat: ifstat.c 16 | $(CC) $(CFLAGS) $(LDFLAGS) -o ifstat ifstat.c $(LIBNETLINK) -lm 17 | 18 | rtacct: rtacct.c 19 | $(CC) $(CFLAGS) $(LDFLAGS) -o rtacct rtacct.c $(LIBNETLINK) -lm 20 | 21 | arpd: arpd.c 22 | $(CC) $(CFLAGS) -I$(DBM_INCLUDE) $(LDFLAGS) -o arpd arpd.c $(LIBNETLINK) -ldb -lpthread 23 | 24 | ssfilter.c: ssfilter.y 25 | bison ssfilter.y -o ssfilter.c 26 | 27 | lnstat: $(LNSTATOBJ) 28 | 29 | install: all 30 | install -m 0755 $(TARGETS) $(DESTDIR)$(SBINDIR) 31 | ln -sf lnstat $(DESTDIR)$(SBINDIR)/rtstat 32 | ln -sf lnstat $(DESTDIR)$(SBINDIR)/ctstat 33 | 34 | clean: 35 | rm -f *.o $(TARGETS) ssfilter.c 36 | -------------------------------------------------------------------------------- /testsuite/tests/policer: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | $TC qdisc del dev $DEV root >/dev/null 2>&1 3 | $TC qdisc add dev $DEV root handle 10:0 cbq bandwidth 100Mbit avpkt 1400 mpu 64 4 | $TC class add dev $DEV parent 10:0 classid 10:12 cbq bandwidth 100mbit rate 100mbit allot 1514 prio 3 maxburst 1 avpkt 500 bounded 5 | $TC filter add dev $DEV parent 10:0 protocol ip prio 10 u32 match ip protocol 1 0xff police rate 2kbit buffer 10k drop flowid 10:12 6 | $TC qdisc list dev $DEV 7 | $TC filter list dev $DEV parent 10:0 8 | $TC qdisc del dev $DEV root 9 | $TC qdisc list dev $DEV 10 | $TC qdisc add dev $DEV root handle 10:0 cbq bandwidth 100Mbit avpkt 1400 mpu 64 11 | $TC class add dev $DEV parent 10:0 classid 10:12 cbq bandwidth 100mbit rate 100mbit allot 1514 prio 3 maxburst 1 avpkt 500 bounded 12 | $TC filter add dev $DEV parent 10:0 protocol ip prio 10 u32 match ip protocol 1 0xff police rate 2kbit buffer 10k drop flowid 10:12 13 | $TC qdisc del dev $DEV root 14 | -------------------------------------------------------------------------------- /include/linux/tc_act/tc_pedit.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_PED_H 2 | #define __LINUX_TC_PED_H 3 | 4 | #include 5 | #include 6 | 7 | #define TCA_ACT_PEDIT 7 8 | 9 | enum { 10 | TCA_PEDIT_UNSPEC, 11 | TCA_PEDIT_TM, 12 | TCA_PEDIT_PARMS, 13 | __TCA_PEDIT_MAX 14 | }; 15 | #define TCA_PEDIT_MAX (__TCA_PEDIT_MAX - 1) 16 | 17 | struct tc_pedit_key { 18 | __u32 mask; /* AND */ 19 | __u32 val; /*XOR */ 20 | __u32 off; /*offset */ 21 | __u32 at; 22 | __u32 offmask; 23 | __u32 shift; 24 | }; 25 | 26 | struct tc_pedit_sel { 27 | tc_gen; 28 | unsigned char nkeys; 29 | unsigned char flags; 30 | struct tc_pedit_key keys[0]; 31 | }; 32 | #define tc_pedit tc_pedit_sel 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /netem/pareto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Pareto distribution table generator 3 | * Taken from the uncopyrighted NISTnet code. 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | 13 | static const double a=3.0; 14 | #define TABLESIZE 16384 15 | #define TABLEFACTOR NETEM_DIST_SCALE 16 | 17 | int 18 | main(int argc, char **argv) 19 | { 20 | int i, n; 21 | double dvalue; 22 | 23 | printf("# This is the distribution table for the pareto distribution.\n"); 24 | 25 | for (i = 65536, n = 0; i > 0; i -= 16) { 26 | dvalue = (double)i/(double)65536; 27 | dvalue = 1.0/pow(dvalue, 1.0/a); 28 | dvalue -= 1.5; 29 | dvalue *= (4.0/3.0)*(double)TABLEFACTOR; 30 | if (dvalue > 32767) 31 | dvalue = 32767; 32 | 33 | printf(" %d", (int)rint(dvalue)); 34 | if (++n == 8) { 35 | putchar('\n'); 36 | n = 0; 37 | } 38 | } 39 | 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /genl/Makefile: -------------------------------------------------------------------------------- 1 | GENLOBJ=genl.o 2 | 3 | include ../Config 4 | SHARED_LIBS ?= y 5 | 6 | CFLAGS += -fno-strict-aliasing 7 | 8 | GENLMODULES := 9 | GENLMODULES += ctrl.o 10 | 11 | GENLOBJ += $(GENLMODULES) 12 | 13 | GENLLIB := 14 | 15 | ifeq ($(SHARED_LIBS),y) 16 | LDFLAGS += -Wl,-export-dynamic 17 | LDLIBS += -lm -ldl 18 | endif 19 | 20 | all: genl 21 | 22 | genl: $(GENLOBJ) $(LIBNETLINK) $(LIBUTIL) $(GENLLIB) 23 | 24 | install: all 25 | install -m 0755 genl $(DESTDIR)$(SBINDIR) 26 | 27 | clean: 28 | rm -f $(GENLOBJ) $(GENLLIB) genl 29 | 30 | ifneq ($(SHARED_LIBS),y) 31 | 32 | genl: static-syms.o 33 | static-syms.o: static-syms.h 34 | static-syms.h: $(wildcard *.c) 35 | files="$^" ; \ 36 | for s in `grep -B 3 '\ $@ 39 | 40 | endif 41 | -------------------------------------------------------------------------------- /tc/p_tcp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * m_pedit_tcp.c packet editor: TCP header 3 | * 4 | * This program is free software; you can distribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: J Hadi Salim (hadi@cyberus.ca) 10 | * 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "utils.h" 23 | #include "tc_util.h" 24 | #include "m_pedit.h" 25 | 26 | static int 27 | parse_tcp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey) 28 | { 29 | int res = -1; 30 | return res; 31 | } 32 | struct m_pedit_util p_pedit_tcp = { 33 | NULL, 34 | "tcp", 35 | parse_tcp, 36 | }; 37 | 38 | 39 | -------------------------------------------------------------------------------- /tc/p_udp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * m_pedit_udp.c packet editor: UDP header 3 | * 4 | * This program is free software; you can distribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: J Hadi Salim (hadi@cyberus.ca) 10 | * 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "utils.h" 23 | #include "tc_util.h" 24 | #include "m_pedit.h" 25 | 26 | static int 27 | parse_udp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey) 28 | { 29 | int res = -1; 30 | return res; 31 | } 32 | 33 | struct m_pedit_util p_pedit_udp = { 34 | NULL, 35 | "udp", 36 | parse_udp, 37 | }; 38 | 39 | -------------------------------------------------------------------------------- /examples/diffserv/ef-prio: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | $TC = "/root/DS-6-beta/iproute2-990530-dsing/tc/tc"; 3 | $DEV = "dev eth1"; 4 | $efrate="1.5Mbit"; 5 | $MTU="1.5kB"; 6 | print "$TC qdisc add $DEV handle 1:0 root dsmark indices 64 set_tc_index\n"; 7 | print "$TC filter add $DEV parent 1:0 protocol ip prio 1 tcindex ". 8 | "mask 0xfc shift 2\n"; 9 | print "$TC qdisc add $DEV parent 1:0 handle 2:0 prio\n"; 10 | # 11 | # EF class: Maximum about one MTU sized packet allowed on the queue 12 | # 13 | print "$TC qdisc add $DEV parent 2:1 tbf rate $efrate burst $MTU limit 1.6kB\n"; 14 | print "$TC filter add $DEV parent 2:0 protocol ip prio 1 ". 15 | "handle 0x2e tcindex classid 2:1 pass_on\n"; 16 | # 17 | # BE class 18 | # 19 | print "#BE class(2:2) \n"; 20 | print "$TC qdisc add $DEV parent 2:2 red limit 60KB ". 21 | "min 15KB max 45KB burst 20 avpkt 1000 bandwidth 10Mbit ". 22 | "probability 0.4\n"; 23 | # 24 | print "$TC filter add $DEV parent 2:0 protocol ip prio 2 ". 25 | "handle 0 tcindex mask 0 classid 2:2 pass_on\n"; 26 | -------------------------------------------------------------------------------- /include/linux/atmapi.h: -------------------------------------------------------------------------------- 1 | /* atmapi.h - ATM API user space/kernel compatibility */ 2 | 3 | /* Written 1999,2000 by Werner Almesberger, EPFL ICA */ 4 | 5 | 6 | #ifndef _LINUX_ATMAPI_H 7 | #define _LINUX_ATMAPI_H 8 | 9 | #if defined(__sparc__) || defined(__ia64__) 10 | /* such alignment is not required on 32 bit sparcs, but we can't 11 | figure that we are on a sparc64 while compiling user-space programs. */ 12 | #define __ATM_API_ALIGN __attribute__((aligned(8))) 13 | #else 14 | #define __ATM_API_ALIGN 15 | #endif 16 | 17 | 18 | /* 19 | * Opaque type for kernel pointers. Note that _ is never accessed. We need 20 | * the struct in order hide the array, so that we can make simple assignments 21 | * instead of being forced to use memcpy. It also improves error reporting for 22 | * code that still assumes that we're passing unsigned longs. 23 | * 24 | * Convention: NULL pointers are passed as a field of all zeroes. 25 | */ 26 | 27 | typedef struct { unsigned char _[8]; } __ATM_API_ALIGN atm_kptr_t; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /tc/tc_core.h: -------------------------------------------------------------------------------- 1 | #ifndef _TC_CORE_H_ 2 | #define _TC_CORE_H_ 1 3 | 4 | #include 5 | #include 6 | 7 | #define TIME_UNITS_PER_SEC 1000000 8 | 9 | enum link_layer { 10 | LINKLAYER_UNSPEC, 11 | LINKLAYER_ETHERNET, 12 | LINKLAYER_ATM, 13 | }; 14 | 15 | 16 | int tc_core_time2big(unsigned time); 17 | unsigned tc_core_time2tick(unsigned time); 18 | unsigned tc_core_tick2time(unsigned tick); 19 | unsigned tc_core_time2ktime(unsigned time); 20 | unsigned tc_core_ktime2time(unsigned ktime); 21 | unsigned tc_calc_xmittime(__u64 rate, unsigned size); 22 | unsigned tc_calc_xmitsize(__u64 rate, unsigned ticks); 23 | int tc_calc_rtable(struct tc_ratespec *r, __u32 *rtab, 24 | int cell_log, unsigned mtu, enum link_layer link_layer); 25 | int tc_calc_size_table(struct tc_sizespec *s, __u16 **stab); 26 | 27 | int tc_setup_estimator(unsigned A, unsigned time_const, struct tc_estimator *est); 28 | 29 | int tc_core_init(void); 30 | 31 | extern struct rtnl_handle g_rth; 32 | extern int is_batch_mode; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /include/linux/tc_act/tc_mirred.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_MIR_H 2 | #define __LINUX_TC_MIR_H 3 | 4 | #include 5 | #include 6 | 7 | #define TCA_ACT_MIRRED 8 8 | #define TCA_EGRESS_REDIR 1 /* packet redirect to EGRESS*/ 9 | #define TCA_EGRESS_MIRROR 2 /* mirror packet to EGRESS */ 10 | #define TCA_INGRESS_REDIR 3 /* packet redirect to INGRESS*/ 11 | #define TCA_INGRESS_MIRROR 4 /* mirror packet to INGRESS */ 12 | 13 | struct tc_mirred { 14 | tc_gen; 15 | int eaction; /* one of IN/EGRESS_MIRROR/REDIR */ 16 | __u32 ifindex; /* ifindex of egress port */ 17 | }; 18 | 19 | enum { 20 | TCA_MIRRED_UNSPEC, 21 | TCA_MIRRED_TM, 22 | TCA_MIRRED_PARMS, 23 | __TCA_MIRRED_MAX 24 | }; 25 | #define TCA_MIRRED_MAX (__TCA_MIRRED_MAX - 1) 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /tc/tc_common.h: -------------------------------------------------------------------------------- 1 | 2 | #define TCA_BUF_MAX (64*1024) 3 | 4 | extern struct rtnl_handle rth; 5 | extern int do_qdisc(int argc, char **argv); 6 | extern int do_class(int argc, char **argv); 7 | extern int do_filter(int argc, char **argv); 8 | extern int do_action(int argc, char **argv); 9 | extern int do_tcmonitor(int argc, char **argv); 10 | extern int print_action(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); 11 | extern int print_filter(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); 12 | extern int print_qdisc(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); 13 | extern int print_class(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg); 14 | extern void print_size_table(FILE *fp, const char *prefix, struct rtattr *rta); 15 | 16 | struct tc_estimator; 17 | extern int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est); 18 | 19 | struct tc_sizespec; 20 | extern int parse_size_table(int *p_argc, char ***p_argv, struct tc_sizespec *s); 21 | extern int check_size_table_opts(struct tc_sizespec *s); 22 | -------------------------------------------------------------------------------- /man/man8/routel.8: -------------------------------------------------------------------------------- 1 | .TH "ROUTEL" "8" "3 Jan, 2008" "iproute2" "Linux" 2 | .SH "NAME" 3 | .LP 4 | routel \- list routes with pretty output format 5 | .br 6 | routef \- flush routes 7 | .SH "SYNTAX" 8 | .LP 9 | routel [\fItablenr\fP [\fIraw ip args...\fP]] 10 | .br 11 | routef 12 | .SH "DESCRIPTION" 13 | .LP 14 | These programs are a set of helper scripts you can use instead of raw iproute2 commands. 15 | .br 16 | The routel script will list routes in a format that some might consider easier to interpret then the ip route list equivalent. 17 | .br 18 | The routef script does not take any arguments and will simply flush the routing table down the drain. Beware! This means deleting all routes which will make your network unusable! 19 | 20 | .SH "FILES" 21 | .LP 22 | \fI/usr/bin/routef\fP 23 | .br 24 | \fI/usr/bin/routel\fP 25 | .SH "AUTHORS" 26 | .LP 27 | The routel script was written by Stephen R. van den Berg , 1999/04/18 and donated to the public domain. 28 | .br 29 | This manual page was written by Andreas Henriksson , for the Debian GNU/Linux system. 30 | .SH "SEE ALSO" 31 | .LP 32 | ip(8) 33 | -------------------------------------------------------------------------------- /man/man8/Makefile: -------------------------------------------------------------------------------- 1 | TARGETS = ip-address.8 ip-link.8 ip-route.8 2 | 3 | MAN8PAGES = $(TARGETS) ip.8 arpd.8 lnstat.8 routel.8 rtacct.8 rtmon.8 ss.8 \ 4 | tc.8 tc-bfifo.8 tc-cbq.8 tc-cbq-details.8 tc-choke.8 tc-codel.8 \ 5 | tc-drr.8 tc-ematch.8 tc-fq_codel.8 tc-hfsc.8 tc-htb.8 \ 6 | tc-netem.8 tc-pfifo.8 tc-pfifo_fast.8 tc-prio.8 tc-red.8 \ 7 | tc-sfb.8 tc-sfq.8 tc-stab.8 tc-tbf.8 \ 8 | bridge.8 rtstat.8 ctstat.8 nstat.8 routef.8 \ 9 | ip-addrlabel.8 ip-l2tp.8 \ 10 | ip-maddress.8 ip-monitor.8 ip-mroute.8 ip-neighbour.8 \ 11 | ip-netns.8 ip-ntable.8 ip-rule.8 ip-tunnel.8 ip-xfrm.8 \ 12 | ip-tcp_metrics.8 ip-netconf.8 13 | 14 | all: $(TARGETS) 15 | 16 | ip-address.8: ip-address.8.in 17 | sed "s|@SYSCONFDIR@|$(CONFDIR)|g" $< > $@ 18 | 19 | ip-link.8: ip-link.8.in 20 | sed "s|@SYSCONFDIR@|$(CONFDIR)|g" $< > $@ 21 | 22 | ip-route.8: ip-route.8.in 23 | sed "s|@SYSCONFDIR@|$(CONFDIR)|g" $< > $@ 24 | 25 | distclean: clean 26 | 27 | clean: 28 | @rm -f $(TARGETS) 29 | 30 | install: 31 | $(INSTALLDIR) $(DESTDIR)$(MANDIR)/man8 32 | $(INSTALLMAN) $(MAN8PAGES) $(DESTDIR)$(MANDIR)/man8 33 | 34 | .PHONY: install clean distclean 35 | -------------------------------------------------------------------------------- /netem/normal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Normal distribution table generator 3 | * Taken from the uncopyrighted NISTnet code. 4 | */ 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #define TABLESIZE 16384 15 | #define TABLEFACTOR NETEM_DIST_SCALE 16 | 17 | static double 18 | normal(double x, double mu, double sigma) 19 | { 20 | return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma)); 21 | } 22 | 23 | 24 | int 25 | main(int argc, char **argv) 26 | { 27 | int i, n; 28 | double x; 29 | double table[TABLESIZE+1]; 30 | 31 | for (x = -10.0; x < 10.05; x += .00005) { 32 | i = rint(TABLESIZE * normal(x, 0.0, 1.0)); 33 | table[i] = x; 34 | } 35 | 36 | 37 | printf("# This is the distribution table for the normal distribution.\n"); 38 | for (i = n = 0; i < TABLESIZE; i += 4) { 39 | int value = (int) rint(table[i]*TABLEFACTOR); 40 | if (value < SHRT_MIN) value = SHRT_MIN; 41 | if (value > SHRT_MAX) value = SHRT_MAX; 42 | 43 | printf(" %d", value); 44 | if (++n == 8) { 45 | putchar('\n'); 46 | n = 0; 47 | } 48 | } 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /man/man8/rtacct.8: -------------------------------------------------------------------------------- 1 | .TH RTACCT 8 "27 June, 2007" 2 | 3 | .SH NAME 4 | nstat, rtacct - network statistics tools. 5 | 6 | .SH SYNOPSIS 7 | Usage: nstat [ -h?vVzrnasd:t: ] [ PATTERN [ PATTERN ] ] 8 | .br 9 | Usage: rtacct [ -h?vVzrnasd:t: ] [ ListOfRealms ] 10 | 11 | .SH DESCRIPTION 12 | .B nstat 13 | and 14 | .B rtacct 15 | are simple tools to monitor kernel snmp counters and network interface statistics. 16 | 17 | .SH OPTIONS 18 | .TP 19 | -h -? 20 | Print help 21 | .TP 22 | -v -V 23 | Print version 24 | .TP 25 | -z 26 | Dump zero counters too. By default they are not shown. 27 | .TP 28 | -r 29 | Reset history. 30 | .TP 31 | -n 32 | Do not display anything, only update history. 33 | .TP 34 | -a 35 | Dump absolute values of counters. The default is to calculate increments since the previous use. 36 | .TP 37 | -s 38 | Do not update history, so that the next time you will see counters including values accumulated to the moment of this measurement too. 39 | .TP 40 | -d 41 | Run in daemon mode collecting statistics. is interval between measurements in seconds. 42 | .TP 43 | -t 44 | Time interval to average rates. Default value is 60 seconds. 45 | 46 | .SH SEE ALSO 47 | lnstat(8) 48 | 49 | -------------------------------------------------------------------------------- /include/rt_names.h: -------------------------------------------------------------------------------- 1 | #ifndef RT_NAMES_H_ 2 | #define RT_NAMES_H_ 1 3 | 4 | #include 5 | 6 | const char *rtnl_rtprot_n2a(int id, char *buf, int len); 7 | const char *rtnl_rtscope_n2a(int id, char *buf, int len); 8 | const char *rtnl_rttable_n2a(__u32 id, char *buf, int len); 9 | const char *rtnl_rtrealm_n2a(int id, char *buf, int len); 10 | const char *rtnl_dsfield_n2a(int id, char *buf, int len); 11 | 12 | int rtnl_rtprot_a2n(__u32 *id, const char *arg); 13 | int rtnl_rtscope_a2n(__u32 *id, const char *arg); 14 | int rtnl_rttable_a2n(__u32 *id, const char *arg); 15 | int rtnl_rtrealm_a2n(__u32 *id, const char *arg); 16 | int rtnl_dsfield_a2n(__u32 *id, const char *arg); 17 | int rtnl_group_a2n(int *id, const char *arg); 18 | 19 | const char *inet_proto_n2a(int proto, char *buf, int len); 20 | int inet_proto_a2n(const char *buf); 21 | 22 | 23 | const char * ll_type_n2a(int type, char *buf, int len); 24 | const char *ll_addr_n2a(unsigned char *addr, int alen, 25 | int type, char *buf, int blen); 26 | int ll_addr_a2n(char *lladdr, int len, const char *arg); 27 | 28 | const char * ll_proto_n2a(unsigned short id, char *buf, int len); 29 | int ll_proto_a2n(unsigned short *id, const char *buf); 30 | 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /tc/tc_estimator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tc_core.c TC core library. 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, 10 | * 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "tc_core.h" 25 | 26 | int tc_setup_estimator(unsigned A, unsigned time_const, struct tc_estimator *est) 27 | { 28 | for (est->interval=0; est->interval<=5; est->interval++) { 29 | if (A <= (1<interval)*(TIME_UNITS_PER_SEC/4)) 30 | break; 31 | } 32 | if (est->interval > 5) 33 | return -1; 34 | est->interval -= 2; 35 | for (est->ewma_log=1; est->ewma_log<32; est->ewma_log++) { 36 | double w = 1.0 - 1.0/(1<ewma_log); 37 | if (A/(-log(w)) > time_const) 38 | break; 39 | } 40 | est->ewma_log--; 41 | if (est->ewma_log==0 || est->ewma_log >= 31) 42 | return -1; 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /testsuite/Makefile: -------------------------------------------------------------------------------- 1 | ## -- Config -- 2 | DEV := lo 3 | PREFIX := sudo 4 | ## -- End Config -- 5 | 6 | TESTS := $(patsubst tests/%,%,$(wildcard tests/*.t)) 7 | IPVERS := $(filter-out iproute2/Makefile,$(wildcard iproute2/*)) 8 | KENV := $(shell cat /proc/config.gz | gunzip | grep ^CONFIG) 9 | 10 | .PHONY: compile listtests alltests configure $(TESTS) 11 | 12 | configure: 13 | echo "Entering iproute2" && cd iproute2 && $(MAKE) configure && cd ..; 14 | 15 | compile: configure 16 | echo "Entering iproute2" && cd iproute2 && $(MAKE) && cd ..; 17 | 18 | listtests: 19 | @for t in $(TESTS); do \ 20 | echo "$$t"; \ 21 | done 22 | 23 | alltests: $(TESTS) 24 | 25 | clean: 26 | @rm -rf results/* 27 | 28 | distclean: clean 29 | echo "Entering iproute2" && cd iproute2 && $(MAKE) distclean && cd ..; 30 | 31 | $(TESTS): 32 | @for i in $(IPVERS); do \ 33 | o=`echo $$i | sed -e 's/iproute2\///'`; \ 34 | echo -n "Running $@ [$$o/`uname -r`]: "; \ 35 | TC="$$i/tc/tc" IP="$$i/ip/ip" DEV="$(DEV)" IPVER="$@" SNAME="$$i" \ 36 | ERRF="results/$@.$$o.err" $(KENV) $(PREFIX) tests/$@ > results/$@.$$o.out; \ 37 | if [ "$$?" = "127" ]; then \ 38 | echo "SKIPPED"; \ 39 | elif [ -e "results/$@.$$o.err" ]; then \ 40 | echo "FAILED"; \ 41 | else \ 42 | echo "PASS"; \ 43 | fi; \ 44 | dmesg > results/$@.$$o.dmesg; \ 45 | done 46 | -------------------------------------------------------------------------------- /man/man8/ip-maddress.8: -------------------------------------------------------------------------------- 1 | .TH IP\-MADDRESS 8 "20 Dec 2011" "iproute2" "Linux" 2 | .SH "NAME" 3 | ip-maddress \- multicast addresses management 4 | .SH "SYNOPSIS" 5 | .sp 6 | .ad l 7 | .in +8 8 | .ti -8 9 | .B ip 10 | .RI "[ " OPTIONS " ]" 11 | .B maddress 12 | .RI " { " COMMAND " | " 13 | .BR help " }" 14 | .sp 15 | .ti -8 16 | 17 | .BR "ip maddress" " [ " add " | " del " ]" 18 | .IB MULTIADDR " dev " NAME 19 | 20 | .ti -8 21 | .BR "ip maddress show" " [ " dev 22 | .IR NAME " ]" 23 | 24 | .SH DESCRIPTION 25 | .B maddress 26 | objects are multicast addresses. 27 | 28 | .SS ip maddress show - list multicast addresses 29 | 30 | .TP 31 | .BI dev " NAME " (default) 32 | the device name. 33 | 34 | .SS ip maddress add - add a multicast address 35 | .SS ip maddress delete - delete a multicast address 36 | these commands attach/detach a static link-layer multicast address 37 | to listen on the interface. 38 | Note that it is impossible to join protocol multicast groups 39 | statically. This command only manages link-layer addresses. 40 | 41 | .TP 42 | .BI address " LLADDRESS " (default) 43 | the link-layer multicast address. 44 | 45 | .TP 46 | .BI dev " NAME" 47 | the device to join/leave this multicast address. 48 | 49 | .SH SEE ALSO 50 | .br 51 | .BR ip (8) 52 | 53 | .SH AUTHOR 54 | Original Manpage by Michail Litvak 55 | -------------------------------------------------------------------------------- /examples/diffserv/efcbq: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | # 3 | $TC = "/root/DS-6-beta/iproute2-990530-dsing/tc/tc"; 4 | $DEV = "dev eth1"; 5 | print "$TC qdisc add $DEV handle 1:0 root dsmark indices 64 set_tc_index\n"; 6 | print "$TC filter add $DEV parent 1:0 protocol ip prio 1 tcindex ". 7 | "mask 0xfc shift 2\n"; 8 | print "$TC qdisc add $DEV parent 1:0 handle 2:0 cbq bandwidth ". 9 | "10Mbit cell 8 avpkt 1000 mpu 64\n"; 10 | # 11 | # EF class 12 | # 13 | print "$TC class add $DEV parent 2:0 classid 2:1 cbq bandwidth ". 14 | "10Mbit rate 1500Kbit avpkt 1000 prio 1 bounded isolated ". 15 | "allot 1514 weight 1 maxburst 10 \n"; 16 | # packet fifo for EF? 17 | print "$TC qdisc add $DEV parent 2:1 pfifo limit 5\n"; 18 | print "$TC filter add $DEV parent 2:0 protocol ip prio 1 ". 19 | "handle 0x2e tcindex classid 2:1 pass_on\n"; 20 | # 21 | # BE class 22 | # 23 | print "#BE class(2:2) \n"; 24 | print "$TC class add $DEV parent 2:0 classid 2:2 cbq bandwidth ". 25 | "10Mbit rate 5Mbit avpkt 1000 prio 7 allot 1514 weight 1 ". 26 | "maxburst 21 borrow split 2:0 defmap 0xffff \n"; 27 | print "$TC qdisc add $DEV parent 2:2 red limit 60KB ". 28 | "min 15KB max 45KB burst 20 avpkt 1000 bandwidth 10Mbit ". 29 | "probability 0.4\n"; 30 | print "$TC filter add $DEV parent 2:0 protocol ip prio 2 ". 31 | "handle 0 tcindex mask 0 classid 2:2 pass_on\n"; 32 | -------------------------------------------------------------------------------- /include/linux/unix_diag.h: -------------------------------------------------------------------------------- 1 | #ifndef __UNIX_DIAG_H__ 2 | #define __UNIX_DIAG_H__ 3 | 4 | #include 5 | 6 | struct unix_diag_req { 7 | __u8 sdiag_family; 8 | __u8 sdiag_protocol; 9 | __u16 pad; 10 | __u32 udiag_states; 11 | __u32 udiag_ino; 12 | __u32 udiag_show; 13 | __u32 udiag_cookie[2]; 14 | }; 15 | 16 | #define UDIAG_SHOW_NAME 0x00000001 /* show name (not path) */ 17 | #define UDIAG_SHOW_VFS 0x00000002 /* show VFS inode info */ 18 | #define UDIAG_SHOW_PEER 0x00000004 /* show peer socket info */ 19 | #define UDIAG_SHOW_ICONS 0x00000008 /* show pending connections */ 20 | #define UDIAG_SHOW_RQLEN 0x00000010 /* show skb receive queue len */ 21 | #define UDIAG_SHOW_MEMINFO 0x00000020 /* show memory info of a socket */ 22 | 23 | struct unix_diag_msg { 24 | __u8 udiag_family; 25 | __u8 udiag_type; 26 | __u8 udiag_state; 27 | __u8 pad; 28 | 29 | __u32 udiag_ino; 30 | __u32 udiag_cookie[2]; 31 | }; 32 | 33 | enum { 34 | UNIX_DIAG_NAME, 35 | UNIX_DIAG_VFS, 36 | UNIX_DIAG_PEER, 37 | UNIX_DIAG_ICONS, 38 | UNIX_DIAG_RQLEN, 39 | UNIX_DIAG_MEMINFO, 40 | UNIX_DIAG_SHUTDOWN, 41 | 42 | UNIX_DIAG_MAX, 43 | }; 44 | 45 | struct unix_diag_vfs { 46 | __u32 udiag_vfs_ino; 47 | __u32 udiag_vfs_dev; 48 | }; 49 | 50 | struct unix_diag_rqlen { 51 | __u32 udiag_rqueue; 52 | __u32 udiag_wqueue; 53 | }; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /include/linux/netfilter/xt_tcpudp.h: -------------------------------------------------------------------------------- 1 | #ifndef _XT_TCPUDP_H 2 | #define _XT_TCPUDP_H 3 | 4 | #include 5 | 6 | /* TCP matching stuff */ 7 | struct xt_tcp { 8 | __u16 spts[2]; /* Source port range. */ 9 | __u16 dpts[2]; /* Destination port range. */ 10 | __u8 option; /* TCP Option iff non-zero*/ 11 | __u8 flg_mask; /* TCP flags mask byte */ 12 | __u8 flg_cmp; /* TCP flags compare byte */ 13 | __u8 invflags; /* Inverse flags */ 14 | }; 15 | 16 | /* Values for "inv" field in struct ipt_tcp. */ 17 | #define XT_TCP_INV_SRCPT 0x01 /* Invert the sense of source ports. */ 18 | #define XT_TCP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */ 19 | #define XT_TCP_INV_FLAGS 0x04 /* Invert the sense of TCP flags. */ 20 | #define XT_TCP_INV_OPTION 0x08 /* Invert the sense of option test. */ 21 | #define XT_TCP_INV_MASK 0x0F /* All possible flags. */ 22 | 23 | /* UDP matching stuff */ 24 | struct xt_udp { 25 | __u16 spts[2]; /* Source port range. */ 26 | __u16 dpts[2]; /* Destination port range. */ 27 | __u8 invflags; /* Inverse flags */ 28 | }; 29 | 30 | /* Values for "invflags" field in struct ipt_udp. */ 31 | #define XT_UDP_INV_SRCPT 0x01 /* Invert the sense of source ports. */ 32 | #define XT_UDP_INV_DSTPT 0x02 /* Invert the sense of dest ports. */ 33 | #define XT_UDP_INV_MASK 0x03 /* All possible flags. */ 34 | 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /misc/lnstat.h: -------------------------------------------------------------------------------- 1 | #ifndef _LNSTAT_H 2 | #define _LNSTAT_H 3 | 4 | #include 5 | 6 | #define LNSTAT_VERSION "0.02 041002" 7 | 8 | #define PROC_NET_STAT "/proc/net/stat" 9 | 10 | #define LNSTAT_MAX_FILES 32 11 | #define LNSTAT_MAX_FIELDS_PER_LINE 32 12 | #define LNSTAT_MAX_FIELD_NAME_LEN 32 13 | 14 | struct lnstat_file; 15 | 16 | struct lnstat_field { 17 | struct lnstat_file *file; 18 | unsigned int num; /* field number in line */ 19 | char name[LNSTAT_MAX_FIELD_NAME_LEN+1]; 20 | unsigned long values[2]; /* two buffers for values */ 21 | unsigned long result; 22 | }; 23 | 24 | struct lnstat_file { 25 | struct lnstat_file *next; 26 | char path[PATH_MAX+1]; 27 | char basename[NAME_MAX+1]; 28 | struct timeval last_read; /* last time of read */ 29 | struct timeval interval; /* interval */ 30 | int compat; /* 1 == backwards compat mode */ 31 | FILE *fp; 32 | unsigned int num_fields; /* number of fields */ 33 | struct lnstat_field fields[LNSTAT_MAX_FIELDS_PER_LINE]; 34 | }; 35 | 36 | 37 | struct lnstat_file *lnstat_scan_dir(const char *path, const int num_req_files, 38 | const char **req_files); 39 | int lnstat_update(struct lnstat_file *lnstat_files); 40 | int lnstat_dump(FILE *outfd, struct lnstat_file *lnstat_files); 41 | struct lnstat_field *lnstat_find_field(struct lnstat_file *lnstat_files, 42 | const char *name); 43 | #endif /* _LNSTAT_H */ 44 | -------------------------------------------------------------------------------- /README.decnet: -------------------------------------------------------------------------------- 1 | 2 | Here are a few quick points about DECnet support... 3 | 4 | o iproute2 is the tool of choice for configuring the DECnet support for 5 | Linux. For many features, it is the only tool which can be used to 6 | configure them. 7 | 8 | o No name resolution is available as yet, all addresses must be 9 | entered numerically. 10 | 11 | o Remember to set the hardware address of the interface using: 12 | 13 | ip link set ethX address xx:xx:xx:xx:xx:xx 14 | (where xx:xx:xx:xx:xx:xx is the MAC address for your DECnet node 15 | address) 16 | 17 | if your Ethernet card won't listen to more than one unicast 18 | mac address at once. If the Linux DECnet stack doesn't talk to 19 | any other DECnet nodes, then check this with tcpdump and if its 20 | a problem, change the mac address (but do this _before_ starting 21 | any other network protocol on the interface) 22 | 23 | o Whilst you can use ip addr add to add more than one DECnet address to an 24 | interface, don't expect addresses which are not the same as the 25 | kernels node address to work properly with 2.4 kernels. This should 26 | be fine with 2.6 kernels as the routing code has been extensively 27 | modified and improved. 28 | 29 | o The DECnet support is currently self contained. It does not depend on 30 | the libdnet library. 31 | 32 | Steve Whitehouse 33 | 34 | -------------------------------------------------------------------------------- /ip/tunnel.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C)2006 USAGI/WIDE Project 3 | * 4 | * This program is free software; you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation; either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program; if not, write to the Free Software 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 | */ 18 | /* 19 | * Author: 20 | * Masahide NAKAMURA @USAGI 21 | */ 22 | #ifndef __TUNNEL_H__ 23 | #define __TUNNEL_H__ 1 24 | 25 | #include 26 | 27 | const char *tnl_strproto(__u8 proto); 28 | 29 | int tnl_get_ioctl(const char *basedev, void *p); 30 | int tnl_add_ioctl(int cmd, const char *basedev, const char *name, void *p); 31 | int tnl_del_ioctl(const char *basedev, const char *name, void *p); 32 | int tnl_prl_ioctl(int cmd, const char *name, void *p); 33 | int tnl_6rd_ioctl(int cmd, const char *name, void *p); 34 | int tnl_ioctl_get_6rd(const char *name, void *p); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /tc/p_icmp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * m_pedit_icmp.c packet editor: ICMP header 3 | * 4 | * This program is free software; you can distribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: J Hadi Salim (hadi@cyberus.ca) 10 | * 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "utils.h" 23 | #include "tc_util.h" 24 | #include "m_pedit.h" 25 | 26 | 27 | static int 28 | parse_icmp(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey) 29 | { 30 | int res = -1; 31 | #if 0 32 | int argc = *argc_p; 33 | char **argv = *argv_p; 34 | 35 | if (argc < 2) 36 | return -1; 37 | 38 | if (strcmp(*argv, "type") == 0) { 39 | NEXT_ARG(); 40 | res = parse_u8(&argc, &argv, 0); 41 | goto done; 42 | } 43 | if (strcmp(*argv, "code") == 0) { 44 | NEXT_ARG(); 45 | res = parse_u8(&argc, &argv, 1); 46 | goto done; 47 | } 48 | return -1; 49 | 50 | done: 51 | *argc_p = argc; 52 | *argv_p = argv; 53 | #endif 54 | return res; 55 | } 56 | 57 | struct m_pedit_util p_pedit_icmp = { 58 | NULL, 59 | "icmp", 60 | parse_icmp, 61 | }; 62 | -------------------------------------------------------------------------------- /include/linux/tc_act/tc_skbedit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008, Intel Corporation. 3 | * 4 | * This program is free software; you can redistribute it and/or modify it 5 | * under the terms and conditions of the GNU General Public License, 6 | * version 2, as published by the Free Software Foundation. 7 | * 8 | * This program is distributed in the hope it will be useful, but WITHOUT 9 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with 14 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 15 | * Place - Suite 330, Boston, MA 02111-1307 USA. 16 | * 17 | * Author: Alexander Duyck 18 | */ 19 | 20 | #ifndef __LINUX_TC_SKBEDIT_H 21 | #define __LINUX_TC_SKBEDIT_H 22 | 23 | #include 24 | 25 | #define TCA_ACT_SKBEDIT 11 26 | 27 | #define SKBEDIT_F_PRIORITY 0x1 28 | #define SKBEDIT_F_QUEUE_MAPPING 0x2 29 | #define SKBEDIT_F_MARK 0x4 30 | 31 | struct tc_skbedit { 32 | tc_gen; 33 | }; 34 | 35 | enum { 36 | TCA_SKBEDIT_UNSPEC, 37 | TCA_SKBEDIT_TM, 38 | TCA_SKBEDIT_PARMS, 39 | TCA_SKBEDIT_PRIORITY, 40 | TCA_SKBEDIT_QUEUE_MAPPING, 41 | TCA_SKBEDIT_MARK, 42 | __TCA_SKBEDIT_MAX 43 | }; 44 | #define TCA_SKBEDIT_MAX (__TCA_SKBEDIT_MAX - 1) 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /lib/ipx_ntop.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include "utils.h" 7 | 8 | static __inline__ int do_digit(char *str, u_int32_t addr, u_int32_t scale, size_t *pos, size_t len) 9 | { 10 | u_int32_t tmp = addr >> (scale * 4); 11 | 12 | if (*pos == len) 13 | return 1; 14 | 15 | tmp &= 0x0f; 16 | if (tmp > 9) 17 | *str = tmp + 'A' - 10; 18 | else 19 | *str = tmp + '0'; 20 | (*pos)++; 21 | 22 | return 0; 23 | } 24 | 25 | static const char *ipx_ntop1(const struct ipx_addr *addr, char *str, size_t len) 26 | { 27 | int i; 28 | size_t pos = 0; 29 | 30 | if (len == 0) 31 | return str; 32 | 33 | for(i = 7; i >= 0; i--) 34 | if (do_digit(str + pos, ntohl(addr->ipx_net), i, &pos, len)) 35 | return str; 36 | 37 | if (pos == len) 38 | return str; 39 | 40 | *(str + pos) = '.'; 41 | pos++; 42 | 43 | for(i = 0; i < 6; i++) { 44 | if (do_digit(str + pos, addr->ipx_node[i], 1, &pos, len)) 45 | return str; 46 | if (do_digit(str + pos, addr->ipx_node[i], 0, &pos, len)) 47 | return str; 48 | } 49 | 50 | if (pos == len) 51 | return str; 52 | 53 | *(str + pos) = 0; 54 | 55 | return str; 56 | } 57 | 58 | 59 | const char *ipx_ntop(int af, const void *addr, char *str, size_t len) 60 | { 61 | switch(af) { 62 | case AF_IPX: 63 | errno = 0; 64 | return ipx_ntop1((struct ipx_addr *)addr, str, len); 65 | default: 66 | errno = EAFNOSUPPORT; 67 | } 68 | 69 | return NULL; 70 | } 71 | 72 | 73 | -------------------------------------------------------------------------------- /man/man8/ip-mroute.8: -------------------------------------------------------------------------------- 1 | .TH IP\-MROUTE 8 "13 Dec 2012" "iproute2" "Linux" 2 | .SH "NAME" 3 | ip-mroute \- multicast routing cache management 4 | .SH "SYNOPSIS" 5 | .sp 6 | .ad l 7 | .in +8 8 | .ti -8 9 | .BR "ip " " [ ip-OPTIONS ] " "mroute show" " [ [ " 10 | .BR " to " " ] " 11 | .IR PREFIX " ] [ " 12 | .B from 13 | .IR PREFIX " ] [ " 14 | .B iif 15 | .IR DEVICE " ] [ " 16 | .B table 17 | .IR TABLE_ID " ] " 18 | 19 | .SH DESCRIPTION 20 | .B mroute 21 | objects are multicast routing cache entries created by a user-level 22 | mrouting daemon (f.e. 23 | .B pimd 24 | or 25 | .B mrouted 26 | ). 27 | 28 | Due to the limitations of the current interface to the multicast routing 29 | engine, it is impossible to change 30 | .B mroute 31 | objects administratively, so we can only display them. This limitation 32 | will be removed in the future. 33 | 34 | .SS ip mroute show - list mroute cache entries 35 | 36 | .TP 37 | .BI to " PREFIX " (default) 38 | the prefix selecting the destination multicast addresses to list. 39 | 40 | .TP 41 | .BI iif " NAME" 42 | the interface on which multicast packets are received. 43 | 44 | .TP 45 | .BI from " PREFIX" 46 | the prefix selecting the IP source addresses of the multicast route. 47 | 48 | .TP 49 | .BI table " TABLE_ID" 50 | the table id selecting the multicast table. It can be 51 | .BR local ", " main ", " default ", " all " or a number." 52 | 53 | .SH SEE ALSO 54 | .br 55 | .BR ip (8) 56 | 57 | .SH AUTHOR 58 | Original Manpage by Michail Litvak 59 | -------------------------------------------------------------------------------- /include/linux/tcp_metrics.h: -------------------------------------------------------------------------------- 1 | /* tcp_metrics.h - TCP Metrics Interface */ 2 | 3 | #ifndef _LINUX_TCP_METRICS_H 4 | #define _LINUX_TCP_METRICS_H 5 | 6 | #include 7 | 8 | /* NETLINK_GENERIC related info 9 | */ 10 | #define TCP_METRICS_GENL_NAME "tcp_metrics" 11 | #define TCP_METRICS_GENL_VERSION 0x1 12 | 13 | enum tcp_metric_index { 14 | TCP_METRIC_RTT, 15 | TCP_METRIC_RTTVAR, 16 | TCP_METRIC_SSTHRESH, 17 | TCP_METRIC_CWND, 18 | TCP_METRIC_REORDERING, 19 | 20 | /* Always last. */ 21 | __TCP_METRIC_MAX, 22 | }; 23 | 24 | #define TCP_METRIC_MAX (__TCP_METRIC_MAX - 1) 25 | 26 | enum { 27 | TCP_METRICS_ATTR_UNSPEC, 28 | TCP_METRICS_ATTR_ADDR_IPV4, /* u32 */ 29 | TCP_METRICS_ATTR_ADDR_IPV6, /* binary */ 30 | TCP_METRICS_ATTR_AGE, /* msecs */ 31 | TCP_METRICS_ATTR_TW_TSVAL, /* u32, raw, rcv tsval */ 32 | TCP_METRICS_ATTR_TW_TS_STAMP, /* s32, sec age */ 33 | TCP_METRICS_ATTR_VALS, /* nested +1, u32 */ 34 | TCP_METRICS_ATTR_FOPEN_MSS, /* u16 */ 35 | TCP_METRICS_ATTR_FOPEN_SYN_DROPS, /* u16, count of drops */ 36 | TCP_METRICS_ATTR_FOPEN_SYN_DROP_TS, /* msecs age */ 37 | TCP_METRICS_ATTR_FOPEN_COOKIE, /* binary */ 38 | 39 | __TCP_METRICS_ATTR_MAX, 40 | }; 41 | 42 | #define TCP_METRICS_ATTR_MAX (__TCP_METRICS_ATTR_MAX - 1) 43 | 44 | enum { 45 | TCP_METRICS_CMD_UNSPEC, 46 | TCP_METRICS_CMD_GET, 47 | TCP_METRICS_CMD_DEL, 48 | 49 | __TCP_METRICS_CMD_MAX, 50 | }; 51 | 52 | #define TCP_METRICS_CMD_MAX (__TCP_METRICS_CMD_MAX - 1) 53 | 54 | #endif /* _LINUX_TCP_METRICS_H */ 55 | -------------------------------------------------------------------------------- /ip/routel: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | #$Id$ 3 | 4 | # 5 | # Script created by: Stephen R. van den Berg , 1999/04/18 6 | # Donated to the public domain. 7 | # 8 | # This script transforms the output of "ip" into more readable text. 9 | # "ip" is the Linux-advanced-routing configuration tool part of the 10 | # iproute package. 11 | # 12 | 13 | test "X-h" = "X$1" && echo "Usage: $0 [tablenr [raw ip args...]]" && exit 64 14 | 15 | test -z "$*" && set 0 16 | 17 | ip route list table "$@" | 18 | while read network rest 19 | do set xx $rest 20 | shift 21 | proto="" 22 | via="" 23 | dev="" 24 | scope="" 25 | src="" 26 | table="" 27 | case $network in 28 | broadcast|local|unreachable) via=$network 29 | network=$1 30 | shift 31 | ;; 32 | esac 33 | while test $# != 0 34 | do 35 | key=$1 36 | val=$2 37 | eval "$key=$val" 38 | shift 2 39 | done 40 | echo "$network $via $src $proto $scope $dev $table" 41 | done | awk -F ' ' ' 42 | BEGIN { 43 | format="%15s%-3s %15s %15s %8s %8s%7s %s\n"; 44 | printf(format,"target","","gateway","source","proto","scope","dev","tbl"); 45 | } 46 | { network=$1; 47 | mask=""; 48 | if(match(network,"/")) 49 | { mask=" "substr(network,RSTART+1); 50 | network=substr(network,0,RSTART); 51 | } 52 | via=$2; 53 | src=$3; 54 | proto=$4; 55 | scope=$5; 56 | dev=$6; 57 | table=$7; 58 | printf(format,network,mask,via,src,proto,scope,dev,table); 59 | } 60 | ' 61 | -------------------------------------------------------------------------------- /ip/Makefile: -------------------------------------------------------------------------------- 1 | IPOBJ=ip.o ipaddress.o ipaddrlabel.o iproute.o iprule.o ipnetns.o \ 2 | rtm_map.o iptunnel.o ip6tunnel.o tunnel.o ipneigh.o ipntable.o iplink.o \ 3 | ipmaddr.o ipmonitor.o ipmroute.o ipprefix.o iptuntap.o \ 4 | ipxfrm.o xfrm_state.o xfrm_policy.o xfrm_monitor.o \ 5 | iplink_vlan.o link_veth.o link_gre.o iplink_can.o \ 6 | iplink_macvlan.o iplink_macvtap.o ipl2tp.o link_vti.o \ 7 | iplink_vxlan.o tcp_metrics.o iplink_ipoib.o ipnetconf.o link_ip6tnl.o \ 8 | link_iptnl.o 9 | 10 | RTMONOBJ=rtmon.o 11 | 12 | include ../Config 13 | 14 | ifeq ($(IP_CONFIG_SETNS),y) 15 | CFLAGS += -DHAVE_SETNS 16 | endif 17 | 18 | ALLOBJ=$(IPOBJ) $(RTMONOBJ) 19 | SCRIPTS=ifcfg rtpr routel routef 20 | TARGETS=ip rtmon 21 | 22 | all: $(TARGETS) $(SCRIPTS) 23 | 24 | ip: $(IPOBJ) $(LIBNETLINK) 25 | 26 | 27 | rtmon: $(RTMONOBJ) 28 | 29 | install: all 30 | install -m 0755 $(TARGETS) $(DESTDIR)$(SBINDIR) 31 | install -m 0755 $(SCRIPTS) $(DESTDIR)$(SBINDIR) 32 | 33 | clean: 34 | rm -f $(ALLOBJ) $(TARGETS) 35 | 36 | SHARED_LIBS ?= y 37 | ifeq ($(SHARED_LIBS),y) 38 | 39 | LDLIBS += -ldl 40 | LDFLAGS += -Wl,-export-dynamic 41 | 42 | else 43 | 44 | ip: static-syms.o 45 | static-syms.o: static-syms.h 46 | static-syms.h: $(wildcard *.c) 47 | files="$^" ; \ 48 | for s in `grep -B 3 '\ $@ 51 | 52 | endif 53 | -------------------------------------------------------------------------------- /doc/rtstat.sgml: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | RTACCT Utility 6 | <author>Robert Olsson 7 | <date>some_negative_number, 20 Dec 2001 8 | 9 | <p> 10 | Here is some code for monitoring the route cache. For systems handling high 11 | network load, servers, routers, firewalls etc the route cache and its garbage 12 | collection is crucial. Linux has a solid implementation. 13 | 14 | <p> 15 | The kernel patch (not required since linux-2.4.7) adds statistics counters 16 | from route cache process into 17 | /proc/net/rt_cache_stat. A companion user mode program presents the statistics 18 | in a vmstat or iostat manner. The ratio between cache hits and misses gives 19 | the flow length. 20 | 21 | <p> 22 | Hopefully it can help understanding performance and DoS and other related 23 | issues. 24 | 25 | <p> An URL where newer versions of this utility can be (probably) found 26 | is ftp://robur.slu.se/pub/Linux/net-development/rt_cache_stat/ 27 | 28 | 29 | <p><bf/Description/ 30 | 31 | <p>The format of the command is: 32 | 33 | <tscreen><verb> 34 | rtstat [ OPTIONS ] 35 | </verb></tscreen> 36 | 37 | <p> <tt/OPTIONS/ are: 38 | 39 | <itemize> 40 | 41 | <item><tt/-h/, <tt/-help/ - show help page and version of the utility. 42 | 43 | <item><tt/-i INTERVAL/ - interval between snapshots, default value is 44 | 2 seconds. 45 | 46 | <item><tt/-s NUMBER/ - whether to print header line. 0 inhibits header line, 47 | 1 prescribes to print it once and 2 (this is default setting) forces header 48 | line each 20 lines. 49 | 50 | </itemize> 51 | 52 | </article> 53 | -------------------------------------------------------------------------------- /lib/dnet_pton.c: -------------------------------------------------------------------------------- 1 | #include <errno.h> 2 | #include <string.h> 3 | #include <sys/types.h> 4 | #include <netinet/in.h> 5 | 6 | #include "utils.h" 7 | 8 | static __inline__ u_int16_t dn_htons(u_int16_t addr) 9 | { 10 | union { 11 | u_int8_t byte[2]; 12 | u_int16_t word; 13 | } u; 14 | 15 | u.word = addr; 16 | return ((u_int16_t)u.byte[0]) | (((u_int16_t)u.byte[1]) << 8); 17 | } 18 | 19 | 20 | static int dnet_num(const char *src, u_int16_t * dst) 21 | { 22 | int rv = 0; 23 | int tmp; 24 | *dst = 0; 25 | 26 | while ((tmp = *src++) != 0) { 27 | tmp -= '0'; 28 | if ((tmp < 0) || (tmp > 9)) 29 | return rv; 30 | 31 | rv++; 32 | (*dst) *= 10; 33 | (*dst) += tmp; 34 | } 35 | 36 | return rv; 37 | } 38 | 39 | static int dnet_pton1(const char *src, struct dn_naddr *dna) 40 | { 41 | u_int16_t addr; 42 | u_int16_t area = 0; 43 | u_int16_t node = 0; 44 | int pos; 45 | 46 | pos = dnet_num(src, &area); 47 | if ((pos == 0) || (area > 63) || (*(src + pos) != '.')) 48 | return 0; 49 | pos = dnet_num(src + pos + 1, &node); 50 | if ((pos == 0) || (node > 1023)) 51 | return 0; 52 | dna->a_len = 2; 53 | addr = dn_htons((area << 10) | node); 54 | memcpy(dna->a_addr, &addr, sizeof(addr)); 55 | 56 | return 1; 57 | } 58 | 59 | int dnet_pton(int af, const char *src, void *addr) 60 | { 61 | int err; 62 | 63 | switch (af) { 64 | case AF_DECnet: 65 | errno = 0; 66 | err = dnet_pton1(src, (struct dn_naddr *)addr); 67 | break; 68 | default: 69 | errno = EAFNOSUPPORT; 70 | err = -1; 71 | } 72 | 73 | return err; 74 | } 75 | -------------------------------------------------------------------------------- /include/linux/gen_stats.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_GEN_STATS_H 2 | #define __LINUX_GEN_STATS_H 3 | 4 | #include <linux/types.h> 5 | 6 | enum { 7 | TCA_STATS_UNSPEC, 8 | TCA_STATS_BASIC, 9 | TCA_STATS_RATE_EST, 10 | TCA_STATS_QUEUE, 11 | TCA_STATS_APP, 12 | __TCA_STATS_MAX, 13 | }; 14 | #define TCA_STATS_MAX (__TCA_STATS_MAX - 1) 15 | 16 | /** 17 | * struct gnet_stats_basic - byte/packet throughput statistics 18 | * @bytes: number of seen bytes 19 | * @packets: number of seen packets 20 | */ 21 | struct gnet_stats_basic { 22 | __u64 bytes; 23 | __u32 packets; 24 | }; 25 | struct gnet_stats_basic_packed { 26 | __u64 bytes; 27 | __u32 packets; 28 | } __attribute__ ((packed)); 29 | 30 | /** 31 | * struct gnet_stats_rate_est - rate estimator 32 | * @bps: current byte rate 33 | * @pps: current packet rate 34 | */ 35 | struct gnet_stats_rate_est { 36 | __u64 bps; 37 | __u32 pps; 38 | }; 39 | 40 | /** 41 | * struct gnet_stats_queue - queuing statistics 42 | * @qlen: queue length 43 | * @backlog: backlog size of queue 44 | * @drops: number of dropped packets 45 | * @requeues: number of requeues 46 | * @overlimits: number of enqueues over the limit 47 | */ 48 | struct gnet_stats_queue { 49 | __u32 qlen; 50 | __u32 backlog; 51 | __u32 drops; 52 | __u32 requeues; 53 | __u32 overlimits; 54 | }; 55 | 56 | /** 57 | * struct gnet_estimator - rate estimator configuration 58 | * @interval: sampling period 59 | * @ewma_log: the log of measurement window weight 60 | */ 61 | struct gnet_estimator { 62 | signed char interval; 63 | unsigned char ewma_log; 64 | }; 65 | 66 | 67 | #endif /* __LINUX_GEN_STATS_H */ 68 | -------------------------------------------------------------------------------- /include/linux/types.h: -------------------------------------------------------------------------------- 1 | #ifndef _LINUX_TYPES_H 2 | #define _LINUX_TYPES_H 3 | 4 | #include <asm/types.h> 5 | 6 | #ifndef __ASSEMBLY__ 7 | 8 | #include <linux/posix_types.h> 9 | 10 | 11 | /* 12 | * Below are truly Linux-specific types that should never collide with 13 | * any application/library that wants linux/types.h. 14 | */ 15 | 16 | #ifdef __CHECKER__ 17 | #define __bitwise__ __attribute__((bitwise)) 18 | #else 19 | #define __bitwise__ 20 | #endif 21 | #ifdef __CHECK_ENDIAN__ 22 | #define __bitwise __bitwise__ 23 | #else 24 | #define __bitwise 25 | #endif 26 | 27 | typedef __u16 __bitwise __le16; 28 | typedef __u16 __bitwise __be16; 29 | typedef __u32 __bitwise __le32; 30 | typedef __u32 __bitwise __be32; 31 | typedef __u64 __bitwise __le64; 32 | typedef __u64 __bitwise __be64; 33 | 34 | typedef __u16 __bitwise __sum16; 35 | typedef __u32 __bitwise __wsum; 36 | 37 | /* 38 | * aligned_u64 should be used in defining kernel<->userspace ABIs to avoid 39 | * common 32/64-bit compat problems. 40 | * 64-bit values align to 4-byte boundaries on x86_32 (and possibly other 41 | * architectures) and to 8-byte boundaries on 64-bit architectures. The new 42 | * aligned_64 type enforces 8-byte alignment so that structs containing 43 | * aligned_64 values have the same alignment on 32-bit and 64-bit architectures. 44 | * No conversions are necessary between 32-bit user-space and a 64-bit kernel. 45 | */ 46 | #define __aligned_u64 __u64 __attribute__((aligned(8))) 47 | #define __aligned_be64 __be64 __attribute__((aligned(8))) 48 | #define __aligned_le64 __le64 __attribute__((aligned(8))) 49 | 50 | #endif /* __ASSEMBLY__ */ 51 | #endif /* _LINUX_TYPES_H */ 52 | -------------------------------------------------------------------------------- /lib/inet_proto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * inet_proto.c 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 | * 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <unistd.h> 16 | #include <syslog.h> 17 | #include <fcntl.h> 18 | #include <sys/socket.h> 19 | #include <netinet/in.h> 20 | #include <netdb.h> 21 | #include <string.h> 22 | 23 | #include "rt_names.h" 24 | #include "utils.h" 25 | 26 | const char *inet_proto_n2a(int proto, char *buf, int len) 27 | { 28 | static char ncache[16]; 29 | static int icache = -1; 30 | struct protoent *pe; 31 | 32 | if (proto == icache) 33 | return ncache; 34 | 35 | pe = getprotobynumber(proto); 36 | if (pe) { 37 | icache = proto; 38 | strncpy(ncache, pe->p_name, 16); 39 | strncpy(buf, pe->p_name, len); 40 | return buf; 41 | } 42 | snprintf(buf, len, "ipproto-%d", proto); 43 | return buf; 44 | } 45 | 46 | int inet_proto_a2n(const char *buf) 47 | { 48 | static char ncache[16]; 49 | static int icache = -1; 50 | struct protoent *pe; 51 | 52 | if (icache>=0 && strcmp(ncache, buf) == 0) 53 | return icache; 54 | 55 | if (buf[0] >= '0' && buf[0] <= '9') { 56 | __u8 ret; 57 | if (get_u8(&ret, buf, 10)) 58 | return -1; 59 | return ret; 60 | } 61 | 62 | pe = getprotobyname(buf); 63 | if (pe) { 64 | icache = pe->p_proto; 65 | strncpy(ncache, pe->p_name, 16); 66 | return pe->p_proto; 67 | } 68 | return -1; 69 | } 70 | 71 | 72 | -------------------------------------------------------------------------------- /tc/README.last: -------------------------------------------------------------------------------- 1 | Kernel code and interface. 2 | -------------------------- 3 | 4 | * Compile time switches 5 | 6 | There is only one, but very important, compile time switch. 7 | It is not settable by "make config", but should be selected 8 | manually and after a bit of thinking in <include/net/pkt_sched.h> 9 | 10 | PSCHED_CLOCK_SOURCE can take three values: 11 | 12 | PSCHED_GETTIMEOFDAY 13 | PSCHED_JIFFIES 14 | PSCHED_CPU 15 | 16 | 17 | PSCHED_GETTIMEOFDAY 18 | 19 | Default setting is the most conservative PSCHED_GETTIMEOFDAY. 20 | It is very slow both because of weird slowness of do_gettimeofday() 21 | and because it forces code to use unnatural "timeval" format, 22 | where microseconds and seconds fields are separate. 23 | Besides that, it will misbehave, when delays exceed 2 seconds 24 | (f.e. very slow links or classes bounded to small slice of bandwidth) 25 | To resume: as only you will get it working, select correct clock 26 | source and forget about PSCHED_GETTIMEOFDAY forever. 27 | 28 | 29 | PSCHED_JIFFIES 30 | 31 | Clock is derived from jiffies. On architectures with HZ=100 32 | granularity of this clock is not enough to make reasonable 33 | bindings to real time. However, taking into account Linux 34 | architecture problems, which force us to use artificial 35 | integrated clock in any case, this switch is not so bad 36 | for schduling even on high speed networks, though policing 37 | is not reliable. 38 | 39 | 40 | PSCHED_CPU 41 | 42 | It is available only for alpha and pentiums with correct 43 | CPU timestamp. It is the fastest way, use it when it is available, 44 | but remember: not all pentiums have this facility, and 45 | a lot of them have clock, broken by APM etc. etc. 46 | 47 | 48 | -------------------------------------------------------------------------------- /lib/libgenl.c: -------------------------------------------------------------------------------- 1 | /* 2 | * libgenl.c GENL library 3 | */ 4 | 5 | #include <stdio.h> 6 | #include <stdlib.h> 7 | #include <unistd.h> 8 | 9 | #include <linux/genetlink.h> 10 | #include "libgenl.h" 11 | 12 | static int genl_parse_getfamily(struct nlmsghdr *nlh) 13 | { 14 | struct rtattr *tb[CTRL_ATTR_MAX + 1]; 15 | struct genlmsghdr *ghdr = NLMSG_DATA(nlh); 16 | int len = nlh->nlmsg_len; 17 | struct rtattr *attrs; 18 | 19 | if (nlh->nlmsg_type != GENL_ID_CTRL) { 20 | fprintf(stderr, "Not a controller message, nlmsg_len=%d " 21 | "nlmsg_type=0x%x\n", nlh->nlmsg_len, nlh->nlmsg_type); 22 | return -1; 23 | } 24 | 25 | len -= NLMSG_LENGTH(GENL_HDRLEN); 26 | 27 | if (len < 0) { 28 | fprintf(stderr, "wrong controller message len %d\n", len); 29 | return -1; 30 | } 31 | 32 | if (ghdr->cmd != CTRL_CMD_NEWFAMILY) { 33 | fprintf(stderr, "Unknown controller command %d\n", ghdr->cmd); 34 | return -1; 35 | } 36 | 37 | attrs = (struct rtattr *) ((char *) ghdr + GENL_HDRLEN); 38 | parse_rtattr(tb, CTRL_ATTR_MAX, attrs, len); 39 | 40 | if (tb[CTRL_ATTR_FAMILY_ID] == NULL) { 41 | fprintf(stderr, "Missing family id TLV\n"); 42 | return -1; 43 | } 44 | 45 | return rta_getattr_u16(tb[CTRL_ATTR_FAMILY_ID]); 46 | } 47 | 48 | int genl_resolve_family(struct rtnl_handle *grth, const char *family) 49 | { 50 | GENL_REQUEST(req, 1024, GENL_ID_CTRL, 0, 0, CTRL_CMD_GETFAMILY, 51 | NLM_F_REQUEST); 52 | 53 | addattr_l(&req.n, sizeof(req), CTRL_ATTR_FAMILY_NAME, 54 | family, strlen(family) + 1); 55 | 56 | if (rtnl_talk(grth, &req.n, 0, 0, &req.n) < 0) { 57 | fprintf(stderr, "Error talking to the kernel\n"); 58 | return -2; 59 | } 60 | 61 | return genl_parse_getfamily(&req.n); 62 | } 63 | 64 | -------------------------------------------------------------------------------- /include/linux/if_addr.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_IF_ADDR_H 2 | #define __LINUX_IF_ADDR_H 3 | 4 | #include <linux/types.h> 5 | #include <linux/netlink.h> 6 | 7 | struct ifaddrmsg { 8 | __u8 ifa_family; 9 | __u8 ifa_prefixlen; /* The prefix length */ 10 | __u8 ifa_flags; /* Flags */ 11 | __u8 ifa_scope; /* Address scope */ 12 | __u32 ifa_index; /* Link index */ 13 | }; 14 | 15 | /* 16 | * Important comment: 17 | * IFA_ADDRESS is prefix address, rather than local interface address. 18 | * It makes no difference for normally configured broadcast interfaces, 19 | * but for point-to-point IFA_ADDRESS is DESTINATION address, 20 | * local address is supplied in IFA_LOCAL attribute. 21 | */ 22 | enum { 23 | IFA_UNSPEC, 24 | IFA_ADDRESS, 25 | IFA_LOCAL, 26 | IFA_LABEL, 27 | IFA_BROADCAST, 28 | IFA_ANYCAST, 29 | IFA_CACHEINFO, 30 | IFA_MULTICAST, 31 | __IFA_MAX, 32 | }; 33 | 34 | #define IFA_MAX (__IFA_MAX - 1) 35 | 36 | /* ifa_flags */ 37 | #define IFA_F_SECONDARY 0x01 38 | #define IFA_F_TEMPORARY IFA_F_SECONDARY 39 | 40 | #define IFA_F_NODAD 0x02 41 | #define IFA_F_OPTIMISTIC 0x04 42 | #define IFA_F_DADFAILED 0x08 43 | #define IFA_F_HOMEADDRESS 0x10 44 | #define IFA_F_DEPRECATED 0x20 45 | #define IFA_F_TENTATIVE 0x40 46 | #define IFA_F_PERMANENT 0x80 47 | 48 | struct ifa_cacheinfo { 49 | __u32 ifa_prefered; 50 | __u32 ifa_valid; 51 | __u32 cstamp; /* created timestamp, hundredths of seconds */ 52 | __u32 tstamp; /* updated timestamp, hundredths of seconds */ 53 | }; 54 | 55 | /* backwards compatibility for userspace */ 56 | #define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg)))) 57 | #define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg)) 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /tc/q_ingress.c: -------------------------------------------------------------------------------- 1 | /* 2 | * 3 | * q_ingress.c INGRESS. 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 8 | * 2 of the License, or (at your option) any later version. 9 | * 10 | * Authors: J Hadi Salim 11 | * 12 | * This is here just in case it is needed 13 | * useless right now; might be useful in the future 14 | * 15 | */ 16 | 17 | #include <stdio.h> 18 | #include <stdlib.h> 19 | #include <unistd.h> 20 | #include <syslog.h> 21 | #include <fcntl.h> 22 | #include <sys/socket.h> 23 | #include <netinet/in.h> 24 | #include <arpa/inet.h> 25 | #include <string.h> 26 | 27 | #include "utils.h" 28 | #include "tc_util.h" 29 | 30 | static void explain(void) 31 | { 32 | fprintf(stderr, "Usage: ... ingress \n"); 33 | } 34 | 35 | static int ingress_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) 36 | { 37 | 38 | if (argc > 0) { 39 | while (argc > 0) { 40 | 41 | if (strcmp(*argv, "handle") == 0) { 42 | NEXT_ARG(); 43 | argc--; argv++; 44 | } else { 45 | fprintf(stderr, "What is \"%s\"?\n", *argv); 46 | explain(); 47 | return -1; 48 | } 49 | } 50 | } 51 | 52 | addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); 53 | return 0; 54 | } 55 | 56 | static int ingress_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) 57 | { 58 | 59 | fprintf(f, "---------------- "); 60 | return 0; 61 | } 62 | 63 | struct qdisc_util ingress_qdisc_util = { 64 | .id = "ingress", 65 | .parse_qopt = ingress_parse_opt, 66 | .print_qopt = ingress_print_opt, 67 | }; 68 | -------------------------------------------------------------------------------- /include/iptables_common.h: -------------------------------------------------------------------------------- 1 | #ifndef _IPTABLES_COMMON_H 2 | #define _IPTABLES_COMMON_H 3 | /* Shared definitions between ipv4 and ipv6. */ 4 | 5 | enum exittype { 6 | OTHER_PROBLEM = 1, 7 | PARAMETER_PROBLEM, 8 | VERSION_PROBLEM, 9 | RESOURCE_PROBLEM 10 | }; 11 | 12 | /* this is a special 64bit data type that is 8-byte aligned */ 13 | #define aligned_u64 unsigned long long __attribute__((aligned(8))) 14 | 15 | extern void exit_printhelp(void) __attribute__((noreturn)); 16 | extern void exit_tryhelp(int) __attribute__((noreturn)); 17 | int check_inverse(const char option[], int *invert, int *optind, int argc); 18 | extern int string_to_number(const char *, 19 | unsigned int, 20 | unsigned int, 21 | unsigned int *); 22 | extern int string_to_number_l(const char *, 23 | unsigned long int, 24 | unsigned long int, 25 | unsigned long *); 26 | extern int string_to_number_ll(const char *, 27 | unsigned long long int, 28 | unsigned long long int, 29 | unsigned long long *); 30 | extern int iptables_insmod(const char *modname, const char *modprobe); 31 | extern int load_iptables_ko(const char *modprobe); 32 | void exit_error(enum exittype, char *, ...)__attribute__((noreturn, 33 | format(printf,2,3))); 34 | extern const char *program_name, *program_version; 35 | extern char *lib_dir; 36 | 37 | #define _init __attribute__((constructor)) my_init 38 | #ifdef NO_SHARED_LIBS 39 | # ifdef _INIT 40 | # undef _init 41 | # define _init _INIT 42 | # endif 43 | extern void init_extensions(void); 44 | #endif 45 | 46 | #define __be32 u_int32_t 47 | #define __le32 u_int32_t 48 | #define __be16 u_int16_t 49 | #define __le16 u_int16_t 50 | 51 | #endif /*_IPTABLES_COMMON_H*/ 52 | -------------------------------------------------------------------------------- /include/linux/netdevice.h: -------------------------------------------------------------------------------- 1 | /* 2 | * INET An implementation of the TCP/IP protocol suite for the LINUX 3 | * operating system. INET is implemented using the BSD Socket 4 | * interface as the means of communication with the user level. 5 | * 6 | * Definitions for the Interfaces handler. 7 | * 8 | * Version: @(#)dev.h 1.0.10 08/12/93 9 | * 10 | * Authors: Ross Biro 11 | * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG> 12 | * Corey Minyard <wf-rch!minyard@relay.EU.net> 13 | * Donald J. Becker, <becker@cesdis.gsfc.nasa.gov> 14 | * Alan Cox, <alan@lxorguk.ukuu.org.uk> 15 | * Bjorn Ekwall. <bj0rn@blox.se> 16 | * Pekka Riikonen <priikone@poseidon.pspt.fi> 17 | * 18 | * This program is free software; you can redistribute it and/or 19 | * modify it under the terms of the GNU General Public License 20 | * as published by the Free Software Foundation; either version 21 | * 2 of the License, or (at your option) any later version. 22 | * 23 | * Moved to /usr/include/linux for NET3 24 | */ 25 | #ifndef _LINUX_NETDEVICE_H 26 | #define _LINUX_NETDEVICE_H 27 | 28 | #include <linux/if.h> 29 | #include <linux/if_ether.h> 30 | #include <linux/if_packet.h> 31 | #include <linux/if_link.h> 32 | 33 | 34 | #define MAX_ADDR_LEN 32 /* Largest hardware address length */ 35 | 36 | /* Initial net device group. All devices belong to group 0 by default. */ 37 | #define INIT_NETDEV_GROUP 0 38 | 39 | 40 | 41 | /* Media selection options. */ 42 | enum { 43 | IF_PORT_UNKNOWN = 0, 44 | IF_PORT_10BASE2, 45 | IF_PORT_10BASET, 46 | IF_PORT_AUI, 47 | IF_PORT_100BASET, 48 | IF_PORT_100BASETX, 49 | IF_PORT_100BASEFX 50 | }; 51 | 52 | 53 | #endif /* _LINUX_NETDEVICE_H */ 54 | -------------------------------------------------------------------------------- /ip/link_veth.c: -------------------------------------------------------------------------------- 1 | /* 2 | * link_veth.c veth driver module 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Pavel Emelianov <xemul@openvz.org> 10 | * 11 | */ 12 | 13 | #include <string.h> 14 | #include <net/if.h> 15 | #include <linux/veth.h> 16 | 17 | #include "utils.h" 18 | #include "ip_common.h" 19 | 20 | static void usage(void) 21 | { 22 | printf("Usage: ip link <options> type veth " 23 | "[peer <options>]\nTo get <options> type " 24 | "'ip link add help'\n"); 25 | } 26 | 27 | static int veth_parse_opt(struct link_util *lu, int argc, char **argv, 28 | struct nlmsghdr *hdr) 29 | { 30 | char *name, *type, *link, *dev; 31 | int err, len; 32 | struct rtattr * data; 33 | int group; 34 | 35 | if (strcmp(argv[0], "peer") != 0) { 36 | usage(); 37 | return -1; 38 | } 39 | 40 | data = NLMSG_TAIL(hdr); 41 | addattr_l(hdr, 1024, VETH_INFO_PEER, NULL, 0); 42 | 43 | hdr->nlmsg_len += sizeof(struct ifinfomsg); 44 | 45 | err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)hdr, 46 | &name, &type, &link, &dev, &group); 47 | if (err < 0) 48 | return err; 49 | 50 | if (name) { 51 | len = strlen(name) + 1; 52 | if (len > IFNAMSIZ) 53 | invarg("\"name\" too long\n", *argv); 54 | addattr_l(hdr, 1024, IFLA_IFNAME, name, len); 55 | } 56 | 57 | data->rta_len = (void *)NLMSG_TAIL(hdr) - (void *)data; 58 | return argc - 1 - err; 59 | } 60 | 61 | struct link_util veth_link_util = { 62 | .id = "veth", 63 | .parse_opt = veth_parse_opt, 64 | }; 65 | -------------------------------------------------------------------------------- /tc/tc_cbq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tc_cbq.c CBQ maintanance routines. 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 | * 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <unistd.h> 16 | #include <syslog.h> 17 | #include <fcntl.h> 18 | #include <math.h> 19 | #include <sys/socket.h> 20 | #include <netinet/in.h> 21 | #include <arpa/inet.h> 22 | #include <string.h> 23 | 24 | #include "tc_core.h" 25 | #include "tc_cbq.h" 26 | 27 | unsigned tc_cbq_calc_maxidle(__u64 bndw, __u64 rate, unsigned avpkt, 28 | int ewma_log, unsigned maxburst) 29 | { 30 | double maxidle; 31 | double g = 1.0 - 1.0/(1<<ewma_log); 32 | double xmt = (double)avpkt/bndw; 33 | 34 | maxidle = xmt*(1-g); 35 | if (bndw != rate && maxburst) { 36 | double vxmt = (double)avpkt/rate - xmt; 37 | vxmt *= (pow(g, -(double)maxburst) - 1); 38 | if (vxmt > maxidle) 39 | maxidle = vxmt; 40 | } 41 | return tc_core_time2tick(maxidle*(1<<ewma_log)*TIME_UNITS_PER_SEC); 42 | } 43 | 44 | unsigned tc_cbq_calc_offtime(__u64 bndw, __u64 rate, unsigned avpkt, 45 | int ewma_log, unsigned minburst) 46 | { 47 | double g = 1.0 - 1.0/(1<<ewma_log); 48 | double offtime = (double)avpkt/rate - (double)avpkt/bndw; 49 | 50 | if (minburst == 0) 51 | return 0; 52 | if (minburst == 1) 53 | offtime *= pow(g, -(double)minburst) - 1; 54 | else 55 | offtime *= 1 + (pow(g, -(double)(minburst-1)) - 1)/(1-g); 56 | return tc_core_time2tick(offtime*TIME_UNITS_PER_SEC); 57 | } 58 | -------------------------------------------------------------------------------- /include/linux/atmioc.h: -------------------------------------------------------------------------------- 1 | /* atmioc.h - ranges for ATM-related ioctl numbers */ 2 | 3 | /* Written 1995-1999 by Werner Almesberger, EPFL LRC/ICA */ 4 | 5 | 6 | /* 7 | * See http://icawww1.epfl.ch/linux-atm/magic.html for the complete list of 8 | * "magic" ioctl numbers. 9 | */ 10 | 11 | 12 | #ifndef _LINUX_ATMIOC_H 13 | #define _LINUX_ATMIOC_H 14 | 15 | #include <asm/ioctl.h> 16 | /* everybody including atmioc.h will also need _IO{,R,W,WR} */ 17 | 18 | #define ATMIOC_PHYCOM 0x00 /* PHY device common ioctls, globally unique */ 19 | #define ATMIOC_PHYCOM_END 0x0f 20 | #define ATMIOC_PHYTYP 0x10 /* PHY dev type ioctls, unique per PHY type */ 21 | #define ATMIOC_PHYTYP_END 0x2f 22 | #define ATMIOC_PHYPRV 0x30 /* PHY dev private ioctls, unique per driver */ 23 | #define ATMIOC_PHYPRV_END 0x4f 24 | #define ATMIOC_SARCOM 0x50 /* SAR device common ioctls, globally unique */ 25 | #define ATMIOC_SARCOM_END 0x50 26 | #define ATMIOC_SARPRV 0x60 /* SAR dev private ioctls, unique per driver */ 27 | #define ATMIOC_SARPRV_END 0x7f 28 | #define ATMIOC_ITF 0x80 /* Interface ioctls, globally unique */ 29 | #define ATMIOC_ITF_END 0x8f 30 | #define ATMIOC_BACKEND 0x90 /* ATM generic backend ioctls, u. per backend */ 31 | #define ATMIOC_BACKEND_END 0xaf 32 | /* 0xb0-0xbf: Reserved for future use */ 33 | #define ATMIOC_AREQUIPA 0xc0 /* Application requested IP over ATM, glob. u. */ 34 | #define ATMIOC_LANE 0xd0 /* LAN Emulation, globally unique */ 35 | #define ATMIOC_MPOA 0xd8 /* MPOA, globally unique */ 36 | #define ATMIOC_CLIP 0xe0 /* Classical IP over ATM control, globally u. */ 37 | #define ATMIOC_CLIP_END 0xef 38 | #define ATMIOC_SPECIAL 0xf0 /* Special-purpose controls, globally unique */ 39 | #define ATMIOC_SPECIAL_END 0xff 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /tc/emp_ematch.y: -------------------------------------------------------------------------------- 1 | %{ 2 | #include <stdio.h> 3 | #include <stdlib.h> 4 | #include <malloc.h> 5 | #include <string.h> 6 | #include "m_ematch.h" 7 | %} 8 | 9 | %locations 10 | %token-table 11 | %error-verbose 12 | %name-prefix="ematch_" 13 | 14 | %union { 15 | unsigned int i; 16 | struct bstr *b; 17 | struct ematch *e; 18 | } 19 | 20 | %{ 21 | extern int ematch_lex(void); 22 | extern void yyerror(const char *s); 23 | extern struct ematch *ematch_root; 24 | extern char *ematch_err; 25 | %} 26 | 27 | %token <i> ERROR 28 | %token <b> ATTRIBUTE 29 | %token <i> AND OR NOT 30 | %type <i> invert relation 31 | %type <e> match expr 32 | %type <b> args 33 | %right AND OR 34 | %start input 35 | %% 36 | input: 37 | /* empty */ 38 | | expr 39 | { ematch_root = $1; } 40 | | expr error 41 | { 42 | ematch_root = $1; 43 | YYACCEPT; 44 | } 45 | ; 46 | 47 | expr: 48 | match 49 | { $$ = $1; } 50 | | match relation expr 51 | { 52 | $1->relation = $2; 53 | $1->next = $3; 54 | $$ = $1; 55 | } 56 | ; 57 | 58 | match: 59 | invert ATTRIBUTE '(' args ')' 60 | { 61 | $2->next = $4; 62 | $$ = new_ematch($2, $1); 63 | if ($$ == NULL) 64 | YYABORT; 65 | } 66 | | invert '(' expr ')' 67 | { 68 | $$ = new_ematch(NULL, $1); 69 | if ($$ == NULL) 70 | YYABORT; 71 | $$->child = $3; 72 | } 73 | ; 74 | 75 | args: 76 | ATTRIBUTE 77 | { $$ = $1; } 78 | | ATTRIBUTE args 79 | { $1->next = $2; } 80 | ; 81 | 82 | relation: 83 | AND 84 | { $$ = TCF_EM_REL_AND; } 85 | | OR 86 | { $$ = TCF_EM_REL_OR; } 87 | ; 88 | 89 | invert: 90 | /* empty */ 91 | { $$ = 0; } 92 | | NOT 93 | { $$ = 1; } 94 | ; 95 | %% 96 | 97 | void yyerror(const char *s) 98 | { 99 | ematch_err = strdup(s); 100 | } 101 | 102 | -------------------------------------------------------------------------------- /testsuite/lib/generic.sh: -------------------------------------------------------------------------------- 1 | 2 | export DEST="127.0.0.1" 3 | 4 | ts_log() 5 | { 6 | echo "$@" 7 | } 8 | 9 | ts_err() 10 | { 11 | ts_log "$@" | tee >> $ERRF 12 | } 13 | 14 | ts_cat() 15 | { 16 | cat "$@" 17 | } 18 | 19 | ts_err_cat() 20 | { 21 | ts_cat "$@" | tee >> $ERRF 22 | } 23 | 24 | ts_tc() 25 | { 26 | SCRIPT=$1; shift 27 | DESC=$1; shift 28 | TMP_ERR=`mktemp /tmp/tc_testsuite.XXXXXX` || exit 29 | TMP_OUT=`mktemp /tmp/tc_testsuite.XXXXXX` || exit 30 | 31 | $TC $@ 2> $TMP_ERR > $TMP_OUT 32 | 33 | if [ -s $TMP_ERR ]; then 34 | ts_err "${SCRIPT}: ${DESC} failed:" 35 | ts_err "command: $TC $@" 36 | ts_err "stderr output:" 37 | ts_err_cat $TMP_ERR 38 | if [ -s $TMP_OUT ]; then 39 | ts_err "stdout output:" 40 | ts_err_cat $TMP_OUT 41 | fi 42 | elif [ -s $TMP_OUT ]; then 43 | echo "${SCRIPT}: ${DESC} succeeded with output:" 44 | cat $TMP_OUT 45 | else 46 | echo "${SCRIPT}: ${DESC} succeeded" 47 | fi 48 | 49 | rm $TMP_ERR $TMP_OUT 50 | } 51 | 52 | ts_ip() 53 | { 54 | SCRIPT=$1; shift 55 | DESC=$1; shift 56 | TMP_ERR=`mktemp /tmp/tc_testsuite.XXXXXX` || exit 57 | TMP_OUT=`mktemp /tmp/tc_testsuite.XXXXXX` || exit 58 | 59 | $IP $@ 2> $TMP_ERR > $TMP_OUT 60 | 61 | if [ -s $TMP_ERR ]; then 62 | ts_err "${SCRIPT}: ${DESC} failed:" 63 | ts_err "command: $IP $@" 64 | ts_err "stderr output:" 65 | ts_err_cat $TMP_ERR 66 | if [ -s $TMP_OUT ]; then 67 | ts_err "stdout output:" 68 | ts_err_cat $TMP_OUT 69 | fi 70 | elif [ -s $TMP_OUT ]; then 71 | echo "${SCRIPT}: ${DESC} succeeded with output:" 72 | cat $TMP_OUT 73 | else 74 | echo "${SCRIPT}: ${DESC} succeeded" 75 | fi 76 | 77 | rm $TMP_ERR $TMP_OUT 78 | } 79 | 80 | ts_qdisc_available() 81 | { 82 | HELPOUT=`$TC qdisc add $1 help 2>&1` 83 | if [ "`echo $HELPOUT | grep \"^Unknown qdisc\"`" ]; then 84 | return 0; 85 | else 86 | return 1; 87 | fi 88 | } 89 | -------------------------------------------------------------------------------- /man/man8/ip-addrlabel.8: -------------------------------------------------------------------------------- 1 | .TH IP\-ADDRLABEL 8 "20 Dec 2011" "iproute2" "Linux" 2 | .SH "NAME" 3 | ip-addrlabel \- protocol address label management 4 | .SH "SYNOPSIS" 5 | .sp 6 | .ad l 7 | .in +8 8 | .ti -8 9 | .B ip 10 | .RI "[ " OPTIONS " ]" 11 | .B addrlabel 12 | .RI " { " COMMAND " | " 13 | .BR help " }" 14 | .sp 15 | 16 | .ti -8 17 | .IR OPTIONS " := { " 18 | \fB\-V\fR[\fIersion\fR] | 19 | \fB\-s\fR[\fItatistics\fR] | 20 | \fB\-r\fR[\fIesolve\fR] | 21 | \fB\-f\fR[\fIamily\fR] { 22 | .BR inet " | " inet6 " | " ipx " | " dnet " | " link " } | " 23 | \fB\-o\fR[\fIneline\fR] } 24 | 25 | .ti -8 26 | .BR "ip addrlabel" " { " add " | " del " } " prefix 27 | .BR PREFIX " [ " 28 | .B dev 29 | .IR DEV " ] [ " 30 | .B label 31 | .IR NUMBER " ]" 32 | 33 | .ti -8 34 | .BR "ip addrlabel" " { " list " | " flush " }" 35 | 36 | .SH "DESCRIPTION" 37 | IPv6 address labels are used for address selection; 38 | they are described in RFC 3484. Precedence is managed by userspace, 39 | and only the label itself is stored in the kernel. 40 | 41 | .SS ip addrlabel add - add an address label 42 | add an address label entry to the kernel. 43 | .TP 44 | .BI prefix " PREFIX" 45 | .TP 46 | .BI dev " DEV" 47 | the outgoing interface. 48 | .TP 49 | .BI label " NUMBER" 50 | the label for the prefix. 51 | 0xffffffff is reserved. 52 | .SS ip addrlabel del - delete an address label 53 | delete an address label entry from the kernel. 54 | .B Arguments: 55 | coincide with the arguments of 56 | .B ip addrlabel add 57 | but the label is not required. 58 | .SS ip addrlabel list - list address labels 59 | list the current address label entries in the kernel. 60 | .SS ip addrlabel flush - flush address labels 61 | flush all address labels in the kernel. This does not restore any default settings. 62 | 63 | .SH SEE ALSO 64 | .br 65 | .BR ip (8) 66 | 67 | .SH AUTHOR 68 | Manpage by Yoshifuji Hideaki / 吉藤英明 69 | 70 | -------------------------------------------------------------------------------- /examples/SYN-DoS.rate.limit: -------------------------------------------------------------------------------- 1 | #! /bin/sh -x 2 | # 3 | # sample script on using the ingress capabilities 4 | # this script shows how one can rate limit incoming SYNs 5 | # Useful for TCP-SYN attack protection. You can use 6 | # IPchains to have more powerful additions to the SYN (eg 7 | # in addition the subnet) 8 | # 9 | #path to various utilities; 10 | #change to reflect yours. 11 | # 12 | IPROUTE=/root/DS-6-beta/iproute2-990530-dsing 13 | TC=$IPROUTE/tc/tc 14 | IP=$IPROUTE/ip/ip 15 | IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains 16 | INDEV=eth2 17 | # 18 | # tag all incoming SYN packets through $INDEV as mark value 1 19 | ############################################################ 20 | $IPCHAINS -A input -i $INDEV -y -m 1 21 | ############################################################ 22 | # 23 | # install the ingress qdisc on the ingress interface 24 | ############################################################ 25 | $TC qdisc add dev $INDEV handle ffff: ingress 26 | ############################################################ 27 | 28 | # 29 | # 30 | # SYN packets are 40 bytes (320 bits) so three SYNs equals 31 | # 960 bits (approximately 1kbit); so we rate limit below 32 | # the incoming SYNs to 3/sec (not very sueful really; but 33 | #serves to show the point - JHS 34 | ############################################################ 35 | $TC filter add dev $INDEV parent ffff: protocol ip prio 50 handle 1 fw \ 36 | police rate 1kbit burst 40 mtu 9k drop flowid :1 37 | ############################################################ 38 | 39 | 40 | # 41 | echo "---- qdisc parameters Ingress ----------" 42 | $TC qdisc ls dev $INDEV 43 | echo "---- Class parameters Ingress ----------" 44 | $TC class ls dev $INDEV 45 | echo "---- filter parameters Ingress ----------" 46 | $TC filter ls dev $INDEV parent ffff: 47 | 48 | #deleting the ingress qdisc 49 | #$TC qdisc del $INDEV ingress 50 | -------------------------------------------------------------------------------- /include/linux/netfilter.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_NETFILTER_H 2 | #define __LINUX_NETFILTER_H 3 | 4 | #include <linux/types.h> 5 | 6 | #include <linux/sysctl.h> 7 | 8 | 9 | /* Responses from hook functions. */ 10 | #define NF_DROP 0 11 | #define NF_ACCEPT 1 12 | #define NF_STOLEN 2 13 | #define NF_QUEUE 3 14 | #define NF_REPEAT 4 15 | #define NF_STOP 5 16 | #define NF_MAX_VERDICT NF_STOP 17 | 18 | /* we overload the higher bits for encoding auxiliary data such as the queue 19 | * number or errno values. Not nice, but better than additional function 20 | * arguments. */ 21 | #define NF_VERDICT_MASK 0x000000ff 22 | 23 | /* extra verdict flags have mask 0x0000ff00 */ 24 | #define NF_VERDICT_FLAG_QUEUE_BYPASS 0x00008000 25 | 26 | /* queue number (NF_QUEUE) or errno (NF_DROP) */ 27 | #define NF_VERDICT_QMASK 0xffff0000 28 | #define NF_VERDICT_QBITS 16 29 | 30 | #define NF_QUEUE_NR(x) ((((x) << 16) & NF_VERDICT_QMASK) | NF_QUEUE) 31 | 32 | #define NF_DROP_ERR(x) (((-x) << 16) | NF_DROP) 33 | 34 | /* only for userspace compatibility */ 35 | /* Generic cache responses from hook functions. 36 | <= 0x2000 is used for protocol-flags. */ 37 | #define NFC_UNKNOWN 0x4000 38 | #define NFC_ALTERED 0x8000 39 | 40 | /* NF_VERDICT_BITS should be 8 now, but userspace might break if this changes */ 41 | #define NF_VERDICT_BITS 16 42 | 43 | enum nf_inet_hooks { 44 | NF_INET_PRE_ROUTING, 45 | NF_INET_LOCAL_IN, 46 | NF_INET_FORWARD, 47 | NF_INET_LOCAL_OUT, 48 | NF_INET_POST_ROUTING, 49 | NF_INET_NUMHOOKS 50 | }; 51 | 52 | enum { 53 | NFPROTO_UNSPEC = 0, 54 | NFPROTO_IPV4 = 2, 55 | NFPROTO_ARP = 3, 56 | NFPROTO_BRIDGE = 7, 57 | NFPROTO_IPV6 = 10, 58 | NFPROTO_DECNET = 12, 59 | NFPROTO_NUMPROTO, 60 | }; 61 | 62 | union nf_inet_addr { 63 | __u32 all[4]; 64 | __be32 ip; 65 | __be32 ip6[4]; 66 | struct in_addr in; 67 | struct in6_addr in6; 68 | }; 69 | 70 | #endif /* __LINUX_NETFILTER_H */ 71 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | This repository has been forked from the kernel.org repository at: 2 | git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git 3 | 4 | Compiling on Debian with 3.6.6 kernel: 5 | sudo apt-get install libdb4o-cil-dev libdb-dev bison flex 6 | make 7 | 8 | 9 | README from original iproute2 repository follows: 10 | -------------------- 11 | 12 | This is a set of utilities for Linux networking. 13 | 14 | Information: 15 | http://www.linuxfoundation.org/collaborate/workgroups/networking/iproute2 16 | 17 | Download: 18 | http://www.kernel.org/pub/linux/utils/net/iproute2/ 19 | 20 | Repository: 21 | git://git.kernel.org/pub/scm/linux/kernel/git/shemminger/iproute2.git 22 | 23 | How to compile this. 24 | -------------------- 25 | 1. libdbm 26 | 27 | arpd needs to have the db4 development libraries. For Debian 28 | users this is the package with a name like libdb4.x-dev. 29 | DBM_INCLUDE points to the directory with db_185.h which 30 | is the include file used by arpd to get to the old format Berkeley 31 | database routines. Often this is in the db-devel package. 32 | 33 | 2. make 34 | 35 | The makefile will automatically build a Config file which 36 | contains whether or not ATM is available, etc. 37 | 38 | 3. To make documentation, cd to doc/ directory , then 39 | look at start of Makefile and set correct values for 40 | PAGESIZE=a4 , ie: a4 , letter ... (string) 41 | PAGESPERPAGE=2 , ie: 1 , 2 ... (numeric) 42 | and make there. It assumes, that latex, dvips and psnup 43 | are in your path. 44 | 45 | 4. This package includes matching sanitized kernel headers because 46 | the build environment may not have up to date versions. See Makefile 47 | if you have special requirements and need to point at different 48 | kernel include files. 49 | 50 | Stephen Hemminger 51 | stephen@networkplumber.org 52 | 53 | Alexey Kuznetsov 54 | kuznet@ms2.inr.ac.ru 55 | -------------------------------------------------------------------------------- /netem/stats.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Experimental data distribution table generator 3 | * Taken from the uncopyrighted NISTnet code (public domain). 4 | * 5 | * Rread in a series of "random" data values, either 6 | * experimentally or generated from some probability distribution. 7 | * From this, report statistics. 8 | */ 9 | 10 | #include <stdio.h> 11 | #include <stdlib.h> 12 | #include <math.h> 13 | #include <malloc.h> 14 | #include <sys/types.h> 15 | #include <sys/stat.h> 16 | 17 | void 18 | stats(FILE *fp) 19 | { 20 | struct stat info; 21 | double *x; 22 | int limit; 23 | int n=0, i; 24 | double mu=0.0, sigma=0.0, sumsquare=0.0, sum=0.0, top=0.0, rho=0.0; 25 | double sigma2=0.0; 26 | 27 | fstat(fileno(fp), &info); 28 | if (info.st_size > 0) { 29 | limit = 2*info.st_size/sizeof(double); /* @@ approximate */ 30 | } else { 31 | limit = 10000; 32 | } 33 | x = (double *)malloc(limit*sizeof(double)); 34 | 35 | for (i=0; i<limit; ++i){ 36 | fscanf(fp, "%lf", &x[i]); 37 | if (feof(fp)) 38 | break; 39 | sumsquare += x[i]*x[i]; 40 | sum += x[i]; 41 | ++n; 42 | } 43 | mu = sum/(double)n; 44 | sigma = sqrt((sumsquare - (double)n*mu*mu)/(double)(n-1)); 45 | 46 | for (i=1; i < n; ++i){ 47 | top += ((double)x[i]-mu)*((double)x[i-1]-mu); 48 | sigma2 += ((double)x[i-1] - mu)*((double)x[i-1] - mu); 49 | 50 | } 51 | rho = top/sigma2; 52 | 53 | printf("mu = %12.6f\n", mu); 54 | printf("sigma = %12.6f\n", sigma); 55 | printf("rho = %12.6f\n", rho); 56 | /*printf("sigma2 = %10.4f\n", sqrt(sigma2/(double)(n-1)));*/ 57 | /*printf("correlation rho = %10.6f\n", top/((double)(n-1)*sigma*sigma));*/ 58 | } 59 | 60 | 61 | int 62 | main(int argc, char **argv) 63 | { 64 | FILE *fp; 65 | 66 | if (argc > 1) { 67 | fp = fopen(argv[1], "r"); 68 | if (!fp) { 69 | perror(argv[1]); 70 | exit(1); 71 | } 72 | } else { 73 | fp = stdin; 74 | } 75 | stats(fp); 76 | return 0; 77 | } 78 | -------------------------------------------------------------------------------- /man/man8/tc-pfifo_fast.8: -------------------------------------------------------------------------------- 1 | .TH PFIFO_FAST 8 "10 January 2002" "iproute2" "Linux" 2 | .SH NAME 3 | pfifo_fast \- three-band first in, first out queue 4 | 5 | .SH DESCRIPTION 6 | pfifo_fast is the default qdisc of each interface. 7 | 8 | Whenever an interface is created, the pfifo_fast qdisc is automatically used 9 | as a queue. If another qdisc is attached, it preempts the default 10 | pfifo_fast, which automatically returns to function when an existing qdisc 11 | is detached. 12 | 13 | In this sense this qdisc is magic, and unlike other qdiscs. 14 | 15 | .SH ALGORITHM 16 | The algorithm is very similar to that of the classful 17 | .BR tc-prio (8) 18 | qdisc. 19 | .B pfifo_fast 20 | is like three 21 | .BR tc-pfifo (8) 22 | queues side by side, where packets can be enqueued in any of the three bands 23 | based on their Type of Service bits or assigned priority. 24 | 25 | Not all three bands are dequeued simultaneously - as long as lower bands 26 | have traffic, higher bands are never dequeued. This can be used to 27 | prioritize interactive traffic or penalize 'lowest cost' traffic. 28 | 29 | Each band can be txqueuelen packets long, as configured with 30 | .BR ifconfig (8) 31 | or 32 | .BR ip (8). 33 | Additional packets coming in are not enqueued but are instead dropped. 34 | 35 | See 36 | .BR tc-prio (8) 37 | for complete details on how TOS bits are translated into bands. 38 | .SH PARAMETERS 39 | .TP 40 | txqueuelen 41 | The length of the three bands depends on the interface txqueuelen, as 42 | specified with 43 | .BR ifconfig (8) 44 | or 45 | .BR ip (8). 46 | 47 | .SH BUGS 48 | Does not maintain statistics and does not show up in tc qdisc ls. This is because 49 | it is the automatic default in the absence of a configured qdisc. 50 | 51 | .SH SEE ALSO 52 | .BR tc (8) 53 | 54 | .SH AUTHORS 55 | Alexey N. Kuznetsov, <kuznet@ms2.inr.ac.ru> 56 | 57 | This manpage maintained by bert hubert <ahu@ds9a.nl> 58 | 59 | 60 | -------------------------------------------------------------------------------- /include/xt-internal.h: -------------------------------------------------------------------------------- 1 | #ifndef _XTABLES_INTERNAL_H 2 | #define _XTABLES_INTERNAL_H 1 3 | 4 | #ifndef XT_LIB_DIR 5 | # define XT_LIB_DIR "/lib/xtables" 6 | #endif 7 | 8 | /* protocol family dependent informations */ 9 | struct afinfo { 10 | /* protocol family */ 11 | int family; 12 | 13 | /* prefix of library name (ex "libipt_" */ 14 | char *libprefix; 15 | 16 | /* used by setsockopt (ex IPPROTO_IP */ 17 | int ipproto; 18 | 19 | /* kernel module (ex "ip_tables" */ 20 | char *kmod; 21 | 22 | /* optname to check revision support of match */ 23 | int so_rev_match; 24 | 25 | /* optname to check revision support of match */ 26 | int so_rev_target; 27 | }; 28 | 29 | enum xt_tryload { 30 | DONT_LOAD, 31 | DURING_LOAD, 32 | TRY_LOAD, 33 | LOAD_MUST_SUCCEED 34 | }; 35 | 36 | struct xtables_rule_match { 37 | struct xtables_rule_match *next; 38 | struct xtables_match *match; 39 | /* Multiple matches of the same type: the ones before 40 | the current one are completed from parsing point of view */ 41 | unsigned int completed; 42 | }; 43 | 44 | extern char *lib_dir; 45 | 46 | extern void *fw_calloc(size_t count, size_t size); 47 | extern void *fw_malloc(size_t size); 48 | 49 | extern const char *modprobe_program; 50 | extern int xtables_insmod(const char *modname, const char *modprobe, int quiet); 51 | extern int load_xtables_ko(const char *modprobe, int quiet); 52 | 53 | /* This is decleared in ip[6]tables.c */ 54 | extern struct afinfo afinfo; 55 | 56 | /* Keeping track of external matches and targets: linked lists. */ 57 | extern struct xtables_match *xtables_matches; 58 | extern struct xtables_target *xtables_targets; 59 | 60 | extern struct xtables_match *find_match(const char *name, enum xt_tryload, 61 | struct xtables_rule_match **match); 62 | extern struct xtables_target *find_target(const char *name, enum xt_tryload); 63 | 64 | extern void _init(void); 65 | 66 | #endif /* _XTABLES_INTERNAL_H */ 67 | -------------------------------------------------------------------------------- /include/linux/fib_rules.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_FIB_RULES_H 2 | #define __LINUX_FIB_RULES_H 3 | 4 | #include <linux/types.h> 5 | #include <linux/rtnetlink.h> 6 | 7 | /* rule is permanent, and cannot be deleted */ 8 | #define FIB_RULE_PERMANENT 0x00000001 9 | #define FIB_RULE_INVERT 0x00000002 10 | #define FIB_RULE_UNRESOLVED 0x00000004 11 | #define FIB_RULE_IIF_DETACHED 0x00000008 12 | #define FIB_RULE_DEV_DETACHED FIB_RULE_IIF_DETACHED 13 | #define FIB_RULE_OIF_DETACHED 0x00000010 14 | 15 | /* try to find source address in routing lookups */ 16 | #define FIB_RULE_FIND_SADDR 0x00010000 17 | 18 | struct fib_rule_hdr { 19 | __u8 family; 20 | __u8 dst_len; 21 | __u8 src_len; 22 | __u8 tos; 23 | 24 | __u8 table; 25 | __u8 res1; /* reserved */ 26 | __u8 res2; /* reserved */ 27 | __u8 action; 28 | 29 | __u32 flags; 30 | }; 31 | 32 | enum { 33 | FRA_UNSPEC, 34 | FRA_DST, /* destination address */ 35 | FRA_SRC, /* source address */ 36 | FRA_IIFNAME, /* interface name */ 37 | #define FRA_IFNAME FRA_IIFNAME 38 | FRA_GOTO, /* target to jump to (FR_ACT_GOTO) */ 39 | FRA_UNUSED2, 40 | FRA_PRIORITY, /* priority/preference */ 41 | FRA_UNUSED3, 42 | FRA_UNUSED4, 43 | FRA_UNUSED5, 44 | FRA_FWMARK, /* mark */ 45 | FRA_FLOW, /* flow/class id */ 46 | FRA_UNUSED6, 47 | FRA_UNUSED7, 48 | FRA_UNUSED8, 49 | FRA_TABLE, /* Extended table id */ 50 | FRA_FWMASK, /* mask for netfilter mark */ 51 | FRA_OIFNAME, 52 | __FRA_MAX 53 | }; 54 | 55 | #define FRA_MAX (__FRA_MAX - 1) 56 | 57 | enum { 58 | FR_ACT_UNSPEC, 59 | FR_ACT_TO_TBL, /* Pass to fixed table */ 60 | FR_ACT_GOTO, /* Jump to another rule */ 61 | FR_ACT_NOP, /* No operation */ 62 | FR_ACT_RES3, 63 | FR_ACT_RES4, 64 | FR_ACT_BLACKHOLE, /* Drop without notification */ 65 | FR_ACT_UNREACHABLE, /* Drop with ENETUNREACH */ 66 | FR_ACT_PROHIBIT, /* Drop with EACCES */ 67 | __FR_ACT_MAX, 68 | }; 69 | 70 | #define FR_ACT_MAX (__FR_ACT_MAX - 1) 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /include/linux/ip6_tunnel.h: -------------------------------------------------------------------------------- 1 | #ifndef _IP6_TUNNEL_H 2 | #define _IP6_TUNNEL_H 3 | 4 | #include <linux/types.h> 5 | 6 | #define IPV6_TLV_TNL_ENCAP_LIMIT 4 7 | #define IPV6_DEFAULT_TNL_ENCAP_LIMIT 4 8 | 9 | /* don't add encapsulation limit if one isn't present in inner packet */ 10 | #define IP6_TNL_F_IGN_ENCAP_LIMIT 0x1 11 | /* copy the traffic class field from the inner packet */ 12 | #define IP6_TNL_F_USE_ORIG_TCLASS 0x2 13 | /* copy the flowlabel from the inner packet */ 14 | #define IP6_TNL_F_USE_ORIG_FLOWLABEL 0x4 15 | /* being used for Mobile IPv6 */ 16 | #define IP6_TNL_F_MIP6_DEV 0x8 17 | /* copy DSCP from the outer packet */ 18 | #define IP6_TNL_F_RCV_DSCP_COPY 0x10 19 | /* copy fwmark from inner packet */ 20 | #define IP6_TNL_F_USE_ORIG_FWMARK 0x20 21 | 22 | struct ip6_tnl_parm { 23 | char name[IFNAMSIZ]; /* name of tunnel device */ 24 | int link; /* ifindex of underlying L2 interface */ 25 | __u8 proto; /* tunnel protocol */ 26 | __u8 encap_limit; /* encapsulation limit for tunnel */ 27 | __u8 hop_limit; /* hop limit for tunnel */ 28 | __be32 flowinfo; /* traffic class and flowlabel for tunnel */ 29 | __u32 flags; /* tunnel flags */ 30 | struct in6_addr laddr; /* local tunnel end-point address */ 31 | struct in6_addr raddr; /* remote tunnel end-point address */ 32 | }; 33 | 34 | struct ip6_tnl_parm2 { 35 | char name[IFNAMSIZ]; /* name of tunnel device */ 36 | int link; /* ifindex of underlying L2 interface */ 37 | __u8 proto; /* tunnel protocol */ 38 | __u8 encap_limit; /* encapsulation limit for tunnel */ 39 | __u8 hop_limit; /* hop limit for tunnel */ 40 | __be32 flowinfo; /* traffic class and flowlabel for tunnel */ 41 | __u32 flags; /* tunnel flags */ 42 | struct in6_addr laddr; /* local tunnel end-point address */ 43 | struct in6_addr raddr; /* remote tunnel end-point address */ 44 | 45 | __be16 i_flags; 46 | __be16 o_flags; 47 | __be32 i_key; 48 | __be32 o_key; 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /man/man8/tc-choke.8: -------------------------------------------------------------------------------- 1 | .TH TC 8 "August 2011" "iproute2" "Linux" 2 | .SH NAME 3 | choke \- choose and keep scheduler 4 | .SH SYNOPSIS 5 | .B tc qdisc ... choke 6 | .B limit 7 | packets 8 | .B min 9 | packets 10 | .B max 11 | packets 12 | .B avpkt 13 | bytes 14 | .B burst 15 | packets 16 | .B [ ecn ] [ bandwidth 17 | rate 18 | .B ] probability 19 | chance 20 | 21 | .SH DESCRIPTION 22 | 23 | CHOKe (CHOose and Keep for responsive flows, CHOose and Kill for unresponsive flows) 24 | is a classless qdisc designed to both identify and penalize flows that monopolize the 25 | queue. CHOKe is a variation of RED, and the configuration is similar to RED. 26 | 27 | .SH ALGORITHM 28 | Once the queue hits a certain average length, a random packet is drawn from the 29 | queue. If both the to-be-queued and the drawn packet belong to the same flow, 30 | both packets are dropped. Otherwise, if the queue length is still below the maximum length, 31 | the new packet has a configurable chance of being marked (which may mean dropped). 32 | If the queue length exceeds 33 | .BR max , 34 | the new packet will always be marked (or dropped). 35 | If the queue length exceeds 36 | .BR limit , 37 | the new packet is always dropped. 38 | 39 | The marking probability computation is the same as used by the RED qdisc. 40 | 41 | .SH PARAMETERS 42 | The parameters are the same as for RED, except that RED uses bytes whereas choke 43 | counts packets. See 44 | .BR tc-red (8) 45 | for a description. 46 | 47 | .SH SOURCE 48 | .TP 49 | o 50 | R. Pan, B. Prabhakar, and K. Psounis, "CHOKe, A Stateless 51 | Active Queue Management Scheme for Approximating Fair Bandwidth Allocation", 52 | IEEE INFOCOM, 2000. 53 | .TP 54 | o 55 | A. Tang, J. Wang, S. Low, "Understanding CHOKe: Throughput and Spatial 56 | Characteristics", IEEE/ACM Transactions on Networking, 2004 57 | 58 | .SH SEE ALSO 59 | .BR tc (8), 60 | .BR tc-red (8) 61 | 62 | .SH AUTHOR 63 | sched_choke was contributed by Stephen Hemminger. 64 | -------------------------------------------------------------------------------- /tc/m_estimator.c: -------------------------------------------------------------------------------- 1 | /* 2 | * m_estimator.c Parse/print estimator module options. 3 | * 4 | * This program is free software; you can u32istribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 | * 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <unistd.h> 16 | #include <syslog.h> 17 | #include <fcntl.h> 18 | #include <sys/socket.h> 19 | #include <netinet/in.h> 20 | #include <arpa/inet.h> 21 | #include <string.h> 22 | 23 | #include "utils.h" 24 | #include "tc_util.h" 25 | #include "tc_common.h" 26 | 27 | static void est_help(void); 28 | 29 | static void est_help(void) 30 | { 31 | fprintf(stderr, "Usage: ... estimator INTERVAL TIME-CONST\n"); 32 | fprintf(stderr, " INTERVAL is interval between measurements\n"); 33 | fprintf(stderr, " TIME-CONST is averaging time constant\n"); 34 | fprintf(stderr, "Example: ... est 1sec 8sec\n"); 35 | } 36 | 37 | int parse_estimator(int *p_argc, char ***p_argv, struct tc_estimator *est) 38 | { 39 | int argc = *p_argc; 40 | char **argv = *p_argv; 41 | unsigned A, time_const; 42 | 43 | NEXT_ARG(); 44 | if (est->ewma_log) 45 | duparg("estimator", *argv); 46 | if (matches(*argv, "help") == 0) 47 | est_help(); 48 | if (get_time(&A, *argv)) 49 | invarg("estimator", "invalid estimator interval"); 50 | NEXT_ARG(); 51 | if (matches(*argv, "help") == 0) 52 | est_help(); 53 | if (get_time(&time_const, *argv)) 54 | invarg("estimator", "invalid estimator time constant"); 55 | if (tc_setup_estimator(A, time_const, est) < 0) { 56 | fprintf(stderr, "Error: estimator parameters are out of range.\n"); 57 | return -1; 58 | } 59 | if (show_raw) 60 | fprintf(stderr, "[estimator i=%u e=%u]\n", est->interval, est->ewma_log); 61 | *p_argc = argc; 62 | *p_argv = argv; 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | PSFILES=ip-cref.ps ip-tunnels.ps api-ip6-flowlabels.ps ss.ps nstat.ps arpd.ps rtstat.ps 2 | # tc-cref.ps 3 | # api-rtnl.tex api-pmtudisc.tex api-news.tex 4 | # iki-netdev.ps iki-neighdst.ps 5 | 6 | 7 | LATEX=latex 8 | DVIPS=dvips 9 | SGML2DVI=sgml2latex 10 | SGML2HTML=sgml2html -s 0 11 | LPR=lpr -Zsduplex 12 | SHELL=bash 13 | PAGESIZE=a4 14 | PAGESPERPAGE=2 15 | 16 | HTMLFILES=$(subst .sgml,.html,$(shell echo *.sgml)) 17 | DVIFILES=$(subst .ps,.dvi,$(PSFILES)) 18 | PDFFILES=$(subst .ps,.pdf,$(PSFILES)) 19 | 20 | 21 | all: pstwocol 22 | 23 | pstwocol: $(PSFILES) 24 | 25 | html: $(HTMLFILES) 26 | 27 | dvi: $(DVIFILES) 28 | 29 | pdf: $(PDFFILES) 30 | 31 | print: $(PSFILES) 32 | $(LPR) $(PSFILES) 33 | 34 | %.tex: %.sgml 35 | $(SGML2DVI) --output=tex $< 36 | 37 | %.dvi: %.sgml 38 | $(SGML2DVI) --output=dvi $< 39 | 40 | %.dvi: %.tex 41 | @set -e; pass=2; echo "Running LaTeX $<"; \ 42 | while [ `$(LATEX) $< </dev/null 2>&1 | \ 43 | grep -c '^\(LaTeX Warning: Label(s) may\|No file \|! Emergency stop\)'` -ge 1 ]; do \ 44 | if [ $$pass -gt 3 ]; then \ 45 | echo "Seems, something is wrong. Try by hands." ; exit 1 ; \ 46 | fi; \ 47 | echo "Re-running LaTeX $<, $${pass}d pass"; pass=$$[$$pass + 1]; \ 48 | done 49 | 50 | %.pdf: %.tex 51 | @set -e; pass=2; echo "Running pdfLaTeX $<"; \ 52 | while [ `pdflatex $< </dev/null 2>&1 | \ 53 | grep -c '^\(LaTeX Warning: Label(s) may\|No file \|! Emergency stop\)'` -ge 1 ]; do \ 54 | if [ $$pass -gt 3 ]; then \ 55 | echo "Seems, something is wrong. Try by hands." ; exit 1 ; \ 56 | fi; \ 57 | echo "Re-running pdfLaTeX $<, $${pass}d pass"; pass=$$[$$pass + 1]; \ 58 | done 59 | #%.pdf: %.ps 60 | # ps2pdf $< 61 | 62 | %.ps: %.dvi 63 | $(DVIPS) $< -o $@ 64 | 65 | %.html: %.sgml 66 | $(SGML2HTML) $< 67 | 68 | install: 69 | install -m 0644 $(shell echo *.tex) $(DESTDIR)$(DOCDIR) 70 | install -m 0644 $(shell echo *.sgml) $(DESTDIR)$(DOCDIR) 71 | 72 | clean: 73 | rm -f *.aux *.log *.toc $(PSFILES) $(DVIFILES) *.html 74 | -------------------------------------------------------------------------------- /include/linux/if_vlan.h: -------------------------------------------------------------------------------- 1 | /* 2 | * VLAN An implementation of 802.1Q VLAN tagging. 3 | * 4 | * Authors: Ben Greear <greearb@candelatech.com> 5 | * 6 | * This program is free software; you can redistribute it and/or 7 | * modify it under the terms of the GNU General Public License 8 | * as published by the Free Software Foundation; either version 9 | * 2 of the License, or (at your option) any later version. 10 | * 11 | */ 12 | 13 | #ifndef _LINUX_IF_VLAN_H_ 14 | #define _LINUX_IF_VLAN_H_ 15 | 16 | 17 | /* VLAN IOCTLs are found in sockios.h */ 18 | 19 | /* Passed in vlan_ioctl_args structure to determine behaviour. */ 20 | enum vlan_ioctl_cmds { 21 | ADD_VLAN_CMD, 22 | DEL_VLAN_CMD, 23 | SET_VLAN_INGRESS_PRIORITY_CMD, 24 | SET_VLAN_EGRESS_PRIORITY_CMD, 25 | GET_VLAN_INGRESS_PRIORITY_CMD, 26 | GET_VLAN_EGRESS_PRIORITY_CMD, 27 | SET_VLAN_NAME_TYPE_CMD, 28 | SET_VLAN_FLAG_CMD, 29 | GET_VLAN_REALDEV_NAME_CMD, /* If this works, you know it's a VLAN device, btw */ 30 | GET_VLAN_VID_CMD /* Get the VID of this VLAN (specified by name) */ 31 | }; 32 | 33 | enum vlan_flags { 34 | VLAN_FLAG_REORDER_HDR = 0x1, 35 | VLAN_FLAG_GVRP = 0x2, 36 | VLAN_FLAG_LOOSE_BINDING = 0x4, 37 | VLAN_FLAG_MVRP = 0x8, 38 | }; 39 | 40 | enum vlan_name_types { 41 | VLAN_NAME_TYPE_PLUS_VID, /* Name will look like: vlan0005 */ 42 | VLAN_NAME_TYPE_RAW_PLUS_VID, /* name will look like: eth1.0005 */ 43 | VLAN_NAME_TYPE_PLUS_VID_NO_PAD, /* Name will look like: vlan5 */ 44 | VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, /* Name will look like: eth0.5 */ 45 | VLAN_NAME_TYPE_HIGHEST 46 | }; 47 | 48 | struct vlan_ioctl_args { 49 | int cmd; /* Should be one of the vlan_ioctl_cmds enum above. */ 50 | char device1[24]; 51 | 52 | union { 53 | char device2[24]; 54 | int VID; 55 | unsigned int skb_priority; 56 | unsigned int name_type; 57 | unsigned int bind_type; 58 | unsigned int flag; /* Matches vlan_dev_priv flags */ 59 | } u; 60 | 61 | short vlan_qos; 62 | }; 63 | 64 | #endif /* _LINUX_IF_VLAN_H_ */ 65 | -------------------------------------------------------------------------------- /netem/paretonormal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Paretoormal distribution table generator 3 | * 4 | * This distribution is simply .25*normal + .75*pareto; a combination 5 | * which seems to match experimentally observed distributions reasonably 6 | * well, but is computationally easy to handle. 7 | * The entries represent a scaled inverse of the cumulative distribution 8 | * function. 9 | * 10 | * Taken from the uncopyrighted NISTnet code. 11 | */ 12 | #include <stdio.h> 13 | #include <stdlib.h> 14 | #include <stdlib.h> 15 | #include <string.h> 16 | #include <math.h> 17 | #include <limits.h> 18 | #include <malloc.h> 19 | 20 | #include <linux/types.h> 21 | #include <linux/pkt_sched.h> 22 | 23 | #define TABLESIZE 16384 24 | #define TABLEFACTOR NETEM_DIST_SCALE 25 | 26 | static double 27 | normal(double x, double mu, double sigma) 28 | { 29 | return .5 + .5*erf((x-mu)/(sqrt(2.0)*sigma)); 30 | } 31 | 32 | static const double a=3.0; 33 | 34 | static int 35 | paretovalue(int i) 36 | { 37 | double dvalue; 38 | 39 | i = 65536-4*i; 40 | dvalue = (double)i/(double)65536; 41 | dvalue = 1.0/pow(dvalue, 1.0/a); 42 | dvalue -= 1.5; 43 | dvalue *= (4.0/3.0)*(double)TABLEFACTOR; 44 | if (dvalue > 32767) 45 | dvalue = 32767; 46 | return (int)rint(dvalue); 47 | } 48 | 49 | int 50 | main(int argc, char **argv) 51 | { 52 | int i,n; 53 | double x; 54 | double table[TABLESIZE+1]; 55 | 56 | for (x = -10.0; x < 10.05; x += .00005) { 57 | i = rint(TABLESIZE*normal(x, 0.0, 1.0)); 58 | table[i] = x; 59 | } 60 | printf( 61 | "# This is the distribution table for the paretonormal distribution.\n" 62 | ); 63 | 64 | for (i = n = 0; i < TABLESIZE; i += 4) { 65 | int normvalue, parvalue, value; 66 | 67 | normvalue = (int) rint(table[i]*TABLEFACTOR); 68 | parvalue = paretovalue(i); 69 | 70 | value = (normvalue+3*parvalue)/4; 71 | if (value < SHRT_MIN) value = SHRT_MIN; 72 | if (value > SHRT_MAX) value = SHRT_MAX; 73 | 74 | printf(" %d", value); 75 | if (++n == 8) { 76 | putchar('\n'); 77 | n = 0; 78 | } 79 | } 80 | 81 | return 0; 82 | } 83 | -------------------------------------------------------------------------------- /man/man8/ip-monitor.8: -------------------------------------------------------------------------------- 1 | .TH IP\-MONITOR 8 "13 Dec 2012" "iproute2" "Linux" 2 | .SH "NAME" 3 | ip-monitor, rtmon \- state monitoring 4 | .SH "SYNOPSIS" 5 | .sp 6 | .ad l 7 | .in +8 8 | .ti -8 9 | .BR "ip " " [ " 10 | .IR ip-OPTIONS " ]" 11 | .BR "monitor" " [ " all " |" 12 | .IR OBJECT-LIST " ] [" 13 | .BI file " FILENAME " 14 | ] 15 | .sp 16 | 17 | .SH DESCRIPTION 18 | The 19 | .B ip 20 | utility can monitor the state of devices, addresses 21 | and routes continuously. This option has a slightly different format. 22 | Namely, the 23 | .B monitor 24 | command is the first in the command line and then the object list follows: 25 | 26 | .BR "ip monitor" " [ " all " |" 27 | .IR OBJECT-LIST " ] [" 28 | .BI file " FILENAME " 29 | ] 30 | 31 | .I OBJECT-LIST 32 | is the list of object types that we want to monitor. 33 | It may contain 34 | .BR link ", " address ", " route ", " mroute ", " prefix ", " 35 | .BR neigh " and " netconf "." 36 | If no 37 | .B file 38 | argument is given, 39 | .B ip 40 | opens RTNETLINK, listens on it and dumps state changes in the format 41 | described in previous sections. 42 | 43 | .P 44 | If the 45 | .BI file 46 | option is given, the program does not listen on RTNETLINK, 47 | but opens the given file, and dumps its contents. The file 48 | should contain RTNETLINK messages saved in binary format. 49 | Such a file can be generated with the 50 | .B rtmon 51 | utility. This utility has a command line syntax similar to 52 | .BR "ip monitor" . 53 | Ideally, 54 | .B rtmon 55 | should be started before the first network configuration command 56 | is issued. F.e. if you insert: 57 | .sp 58 | .in +8 59 | rtmon file /var/log/rtmon.log 60 | .in -8 61 | .sp 62 | in a startup script, you will be able to view the full history 63 | later. 64 | 65 | .P 66 | Nevertheless, it is possible to start 67 | .B rtmon 68 | at any time. 69 | It prepends the history with the state snapshot dumped at the moment 70 | of starting. 71 | 72 | .SH SEE ALSO 73 | .br 74 | .BR ip (8) 75 | 76 | .SH AUTHOR 77 | Original Manpage by Michail Litvak <mci@owl.openwall.com> 78 | -------------------------------------------------------------------------------- /include/linux/genetlink.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_GENERIC_NETLINK_H 2 | #define __LINUX_GENERIC_NETLINK_H 3 | 4 | #include <linux/types.h> 5 | #include <linux/netlink.h> 6 | 7 | #define GENL_NAMSIZ 16 /* length of family name */ 8 | 9 | #define GENL_MIN_ID NLMSG_MIN_TYPE 10 | #define GENL_MAX_ID 1023 11 | 12 | struct genlmsghdr { 13 | __u8 cmd; 14 | __u8 version; 15 | __u16 reserved; 16 | }; 17 | 18 | #define GENL_HDRLEN NLMSG_ALIGN(sizeof(struct genlmsghdr)) 19 | 20 | #define GENL_ADMIN_PERM 0x01 21 | #define GENL_CMD_CAP_DO 0x02 22 | #define GENL_CMD_CAP_DUMP 0x04 23 | #define GENL_CMD_CAP_HASPOL 0x08 24 | 25 | /* 26 | * List of reserved static generic netlink identifiers: 27 | */ 28 | #define GENL_ID_GENERATE 0 29 | #define GENL_ID_CTRL NLMSG_MIN_TYPE 30 | 31 | /************************************************************************** 32 | * Controller 33 | **************************************************************************/ 34 | 35 | enum { 36 | CTRL_CMD_UNSPEC, 37 | CTRL_CMD_NEWFAMILY, 38 | CTRL_CMD_DELFAMILY, 39 | CTRL_CMD_GETFAMILY, 40 | CTRL_CMD_NEWOPS, 41 | CTRL_CMD_DELOPS, 42 | CTRL_CMD_GETOPS, 43 | CTRL_CMD_NEWMCAST_GRP, 44 | CTRL_CMD_DELMCAST_GRP, 45 | CTRL_CMD_GETMCAST_GRP, /* unused */ 46 | __CTRL_CMD_MAX, 47 | }; 48 | 49 | #define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1) 50 | 51 | enum { 52 | CTRL_ATTR_UNSPEC, 53 | CTRL_ATTR_FAMILY_ID, 54 | CTRL_ATTR_FAMILY_NAME, 55 | CTRL_ATTR_VERSION, 56 | CTRL_ATTR_HDRSIZE, 57 | CTRL_ATTR_MAXATTR, 58 | CTRL_ATTR_OPS, 59 | CTRL_ATTR_MCAST_GROUPS, 60 | __CTRL_ATTR_MAX, 61 | }; 62 | 63 | #define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1) 64 | 65 | enum { 66 | CTRL_ATTR_OP_UNSPEC, 67 | CTRL_ATTR_OP_ID, 68 | CTRL_ATTR_OP_FLAGS, 69 | __CTRL_ATTR_OP_MAX, 70 | }; 71 | 72 | #define CTRL_ATTR_OP_MAX (__CTRL_ATTR_OP_MAX - 1) 73 | 74 | enum { 75 | CTRL_ATTR_MCAST_GRP_UNSPEC, 76 | CTRL_ATTR_MCAST_GRP_NAME, 77 | CTRL_ATTR_MCAST_GRP_ID, 78 | __CTRL_ATTR_MCAST_GRP_MAX, 79 | }; 80 | 81 | #define CTRL_ATTR_MCAST_GRP_MAX (__CTRL_ATTR_MCAST_GRP_MAX - 1) 82 | 83 | 84 | #endif /* __LINUX_GENERIC_NETLINK_H */ 85 | -------------------------------------------------------------------------------- /testsuite/tests/cls-testbed.t: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # vim: ft=sh 3 | 4 | source lib/generic.sh 5 | 6 | QDISCS="cbq htb dsmark" 7 | 8 | for q in ${QDISCS}; do 9 | ts_log "Preparing classifier testbed with qdisc $q" 10 | 11 | for c in tests/cls/*.t; do 12 | 13 | case "$q" in 14 | cbq) 15 | ts_tc "cls-testbed" "cbq root qdisc creation" \ 16 | qdisc add dev $DEV root handle 10:0 \ 17 | cbq bandwidth 100Mbit avpkt 1400 mpu 64 18 | ts_tc "cls-testbed" "cbq root class creation" \ 19 | class add dev $DEV parent 10:0 classid 10:12 \ 20 | cbq bandwidth 100mbit rate 100mbit allot 1514 prio 3 \ 21 | maxburst 1 avpkt 500 bounded 22 | ;; 23 | htb) 24 | ts_qdisc_available "htb" 25 | if [ $? -eq 0 ]; then 26 | ts_log "cls-testbed: HTB is unsupported by $TC, skipping" 27 | continue; 28 | fi 29 | ts_tc "cls-testbed" "htb root qdisc creation" \ 30 | qdisc add dev $DEV root handle 10:0 htb 31 | ts_tc "cls-testbed" "htb root class creation" \ 32 | class add dev $DEV parent 10:0 classid 10:12 \ 33 | htb rate 100Mbit quantum 1514 34 | ;; 35 | dsmark) 36 | ts_qdisc_available "dsmark" 37 | if [ $? -eq 0 ]; then 38 | ts_log "cls-testbed: dsmark is unsupported by $TC, skipping" 39 | continue; 40 | fi 41 | ts_tc "cls-testbed" "dsmark root qdisc creation" \ 42 | qdisc add dev $DEV root handle 20:0 \ 43 | dsmark indices 64 default_index 1 set_tc_index 44 | ts_tc "cls-testbed" "dsmark class creation" \ 45 | class change dev $DEV parent 20:0 classid 20:12 \ 46 | dsmark mask 0xff value 2 47 | ts_tc "cls-testbed" "prio inner qdisc creation" \ 48 | qdisc add dev $DEV parent 20:0 handle 10:0 prio 49 | ;; 50 | *) 51 | ts_err "cls-testbed: no testbed configuration found for qdisc $q" 52 | continue 53 | ;; 54 | esac 55 | 56 | ts_tc "cls-testbed" "tree listing" qdisc list dev eth0 57 | ts_tc "cls-testbed" "tree class listing" class list dev eth0 58 | ts_log "cls-testbed: starting classifier test $c" 59 | $c 60 | 61 | case "$q" in 62 | *) 63 | ts_tc "cls-testbed" "generic qdisc tree deletion" \ 64 | qdisc del dev $DEV root 65 | ;; 66 | esac 67 | done 68 | done 69 | -------------------------------------------------------------------------------- /lib/ipx_pton.c: -------------------------------------------------------------------------------- 1 | #include <errno.h> 2 | #include <string.h> 3 | #include <sys/types.h> 4 | #include <sys/socket.h> 5 | #include <netinet/in.h> 6 | 7 | #include "utils.h" 8 | 9 | static u_int32_t hexget(char c) 10 | { 11 | if (c >= 'A' && c <= 'F') 12 | return c - 'A' + 10; 13 | if (c >= 'a' && c <= 'f') 14 | return c - 'a' + 10; 15 | if (c >= '0' && c <= '9') 16 | return c - '0'; 17 | 18 | return 0xf0; 19 | } 20 | 21 | static int ipx_getnet(u_int32_t *net, const char *str) 22 | { 23 | int i; 24 | u_int32_t tmp; 25 | 26 | for(i = 0; *str && (i < 8); i++) { 27 | 28 | if ((tmp = hexget(*str)) & 0xf0) { 29 | if (*str == '.') 30 | return 0; 31 | else 32 | return -1; 33 | } 34 | 35 | str++; 36 | (*net) <<= 4; 37 | (*net) |= tmp; 38 | } 39 | 40 | if (*str == 0) 41 | return 0; 42 | 43 | return -1; 44 | } 45 | 46 | static int ipx_getnode(u_int8_t *node, const char *str) 47 | { 48 | int i; 49 | u_int32_t tmp; 50 | 51 | for(i = 0; i < 6; i++) { 52 | if ((tmp = hexget(*str++)) & 0xf0) 53 | return -1; 54 | node[i] = (u_int8_t)tmp; 55 | node[i] <<= 4; 56 | if ((tmp = hexget(*str++)) & 0xf0) 57 | return -1; 58 | node[i] |= (u_int8_t)tmp; 59 | if (*str == ':') 60 | str++; 61 | } 62 | 63 | return 0; 64 | } 65 | 66 | static int ipx_pton1(const char *src, struct ipx_addr *addr) 67 | { 68 | char *sep = (char *)src; 69 | int no_node = 0; 70 | 71 | memset(addr, 0, sizeof(struct ipx_addr)); 72 | 73 | while(*sep && (*sep != '.')) 74 | sep++; 75 | 76 | if (*sep != '.') 77 | no_node = 1; 78 | 79 | if (ipx_getnet(&addr->ipx_net, src)) 80 | return 0; 81 | 82 | addr->ipx_net = htonl(addr->ipx_net); 83 | 84 | if (no_node) 85 | return 1; 86 | 87 | if (ipx_getnode(addr->ipx_node, sep + 1)) 88 | return 0; 89 | 90 | return 1; 91 | } 92 | 93 | int ipx_pton(int af, const char *src, void *addr) 94 | { 95 | int err; 96 | 97 | switch (af) { 98 | case AF_IPX: 99 | errno = 0; 100 | err = ipx_pton1(src, (struct ipx_addr *)addr); 101 | break; 102 | default: 103 | errno = EAFNOSUPPORT; 104 | err = -1; 105 | } 106 | 107 | return err; 108 | } 109 | -------------------------------------------------------------------------------- /man/man8/rtmon.8: -------------------------------------------------------------------------------- 1 | .TH RTMON 8 2 | .SH NAME 3 | rtmon \- listens to and monitors RTnetlink 4 | .SH SYNOPSIS 5 | .B rtmon 6 | .RI "[ options ] file FILE [ all | LISTofOBJECTS ]" 7 | .SH DESCRIPTION 8 | This manual page documents briefly the 9 | .B rtmon 10 | command. 11 | .PP 12 | .B rtmon 13 | listens on 14 | .I netlink 15 | socket and monitors routing table changes. 16 | 17 | .I rtmon 18 | can be started before the first network configuration command is issued. 19 | For example if you insert: 20 | 21 | .B rtmon file /var/log/rtmon.log 22 | 23 | in a startup script, you will be able to view the full history later. 24 | Certainly, it is possible to start rtmon at any time. It prepends the history with the state snapshot dumped at the moment of starting. 25 | 26 | .SH OPTIONS 27 | .I rtmon supports the following options: 28 | .TP 29 | .B \-Version 30 | Print version and exit. 31 | .TP 32 | .B help 33 | Show summary of options. 34 | .TP 35 | .B file FILE [ all | LISTofOBJECTS ] 36 | Log output to FILE. LISTofOBJECTS is the list of object types that we 37 | want to monitor. It may contain 'link', 'address', 'route' 38 | and 'all'. 'link' specifies the network device, 'address' the protocol 39 | (IP or IPv6) address on a device, 'route' the routing table entry 40 | and 'all' does what the name says. 41 | .TP 42 | .B \-family [ inet | inet6 | link | help ] 43 | Specify protocol family. 'inet' is IPv4, 'inet6' is IPv6, 'link' 44 | means that no networking protocol is involved and 'help' prints usage information. 45 | .TP 46 | .B \-4 47 | Use IPv4. Shortcut for -family inet. 48 | .TP 49 | .B \-6 50 | Use IPv6. Shortcut for -family inet6. 51 | .TP 52 | .B \-0 53 | Use a special family identifier meaning that no networking protocol is involved. Shortcut for -family link. 54 | .SH USAGE EXAMPLES 55 | .TP 56 | .B # rtmon file /var/log/rtmon.log 57 | Log to file /var/log/rtmon.log, then run: 58 | .TP 59 | .B # ip monitor file /var/log/rtmon.log 60 | to display logged output from file. 61 | .SH SEE ALSO 62 | .BR ip (8) 63 | .SH AUTHOR 64 | .B rtmon 65 | was written by Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>. 66 | .PP 67 | This manual page was written by Michael Prokop <mika@grml.org>, 68 | for the Debian project (but may be used by others). 69 | -------------------------------------------------------------------------------- /tc/tc_red.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tc_red.c RED maintanance routines. 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 | * 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <unistd.h> 16 | #include <syslog.h> 17 | #include <fcntl.h> 18 | #include <math.h> 19 | #include <sys/socket.h> 20 | #include <netinet/in.h> 21 | #include <arpa/inet.h> 22 | #include <string.h> 23 | 24 | #include "tc_core.h" 25 | #include "tc_red.h" 26 | 27 | /* 28 | Plog = log(prob/(qmax - qmin)) 29 | */ 30 | int tc_red_eval_P(unsigned qmin, unsigned qmax, double prob) 31 | { 32 | int i = qmax - qmin; 33 | 34 | if (i <= 0) 35 | return -1; 36 | 37 | prob /= i; 38 | 39 | for (i=0; i<32; i++) { 40 | if (prob > 1.0) 41 | break; 42 | prob *= 2; 43 | } 44 | if (i>=32) 45 | return -1; 46 | return i; 47 | } 48 | 49 | /* 50 | burst + 1 - qmin/avpkt < (1-(1-W)^burst)/W 51 | */ 52 | 53 | int tc_red_eval_ewma(unsigned qmin, unsigned burst, unsigned avpkt) 54 | { 55 | int wlog = 1; 56 | double W = 0.5; 57 | double a = (double)burst + 1 - (double)qmin/avpkt; 58 | 59 | if (a < 1.0) { 60 | fprintf(stderr, "tc_red_eval_ewma() burst %u is too small ?" 61 | " Try burst %u\n", burst, 1 + qmin/avpkt); 62 | return -1; 63 | } 64 | for (wlog=1; wlog<32; wlog++, W /= 2) { 65 | if (a <= (1 - pow(1-W, burst))/W) 66 | return wlog; 67 | } 68 | return -1; 69 | } 70 | 71 | /* 72 | Stab[t>>Scell_log] = -log(1-W) * t/xmit_time 73 | */ 74 | 75 | int tc_red_eval_idle_damping(int Wlog, unsigned avpkt, __u64 bps, __u8 *sbuf) 76 | { 77 | double xmit_time = tc_calc_xmittime(bps, avpkt); 78 | double lW = -log(1.0 - 1.0/(1<<Wlog))/xmit_time; 79 | double maxtime = 31/lW; 80 | int clog; 81 | int i; 82 | 83 | for (clog=0; clog<32; clog++) { 84 | if (maxtime/(1<<clog) < 512) 85 | break; 86 | } 87 | if (clog >= 32) 88 | return -1; 89 | 90 | sbuf[0] = 0; 91 | for (i=1; i<255; i++) { 92 | sbuf[i] = (i<<clog)*lW; 93 | if (sbuf[i] > 31) 94 | sbuf[i] = 31; 95 | } 96 | sbuf[255] = 31; 97 | return clog; 98 | } 99 | -------------------------------------------------------------------------------- /lib/dnet_ntop.c: -------------------------------------------------------------------------------- 1 | #include <errno.h> 2 | #include <string.h> 3 | #include <sys/types.h> 4 | #include <netinet/in.h> 5 | 6 | #include "utils.h" 7 | 8 | static __inline__ u_int16_t dn_ntohs(u_int16_t addr) 9 | { 10 | union { 11 | u_int8_t byte[2]; 12 | u_int16_t word; 13 | } u; 14 | 15 | u.word = addr; 16 | return ((u_int16_t)u.byte[0]) | (((u_int16_t)u.byte[1]) << 8); 17 | } 18 | 19 | static __inline__ int do_digit(char *str, u_int16_t *addr, u_int16_t scale, size_t *pos, size_t len, int *started) 20 | { 21 | u_int16_t tmp = *addr / scale; 22 | 23 | if (*pos == len) 24 | return 1; 25 | 26 | if (((tmp) > 0) || *started || (scale == 1)) { 27 | *str = tmp + '0'; 28 | *started = 1; 29 | (*pos)++; 30 | *addr -= (tmp * scale); 31 | } 32 | 33 | return 0; 34 | } 35 | 36 | 37 | static const char *dnet_ntop1(const struct dn_naddr *dna, char *str, size_t len) 38 | { 39 | u_int16_t addr, area; 40 | size_t pos = 0; 41 | int started = 0; 42 | 43 | memcpy(&addr, dna->a_addr, sizeof(addr)); 44 | addr = dn_ntohs(addr); 45 | area = addr >> 10; 46 | 47 | if (dna->a_len != 2) 48 | return NULL; 49 | 50 | addr &= 0x03ff; 51 | 52 | if (len == 0) 53 | return str; 54 | 55 | if (do_digit(str + pos, &area, 10, &pos, len, &started)) 56 | return str; 57 | 58 | if (do_digit(str + pos, &area, 1, &pos, len, &started)) 59 | return str; 60 | 61 | if (pos == len) 62 | return str; 63 | 64 | *(str + pos) = '.'; 65 | pos++; 66 | started = 0; 67 | 68 | if (do_digit(str + pos, &addr, 1000, &pos, len, &started)) 69 | return str; 70 | 71 | if (do_digit(str + pos, &addr, 100, &pos, len, &started)) 72 | return str; 73 | 74 | if (do_digit(str + pos, &addr, 10, &pos, len, &started)) 75 | return str; 76 | 77 | if (do_digit(str + pos, &addr, 1, &pos, len, &started)) 78 | return str; 79 | 80 | if (pos == len) 81 | return str; 82 | 83 | *(str + pos) = 0; 84 | 85 | return str; 86 | } 87 | 88 | 89 | const char *dnet_ntop(int af, const void *addr, char *str, size_t len) 90 | { 91 | switch(af) { 92 | case AF_DECnet: 93 | errno = 0; 94 | return dnet_ntop1((struct dn_naddr *)addr, str, len); 95 | default: 96 | errno = EAFNOSUPPORT; 97 | } 98 | 99 | return NULL; 100 | } 101 | 102 | 103 | -------------------------------------------------------------------------------- /examples/diffserv/Edge1: -------------------------------------------------------------------------------- 1 | #! /bin/sh -x 2 | # 3 | # sample script on using the ingress capabilities 4 | # This script just tags on the ingress interfac using Ipchains 5 | # the result is used for fast classification and re-marking 6 | # on the egress interface 7 | # 8 | #path to various utilities; 9 | #change to reflect yours. 10 | # 11 | IPROUTE=/root/DS-6-beta/iproute2-990530-dsing 12 | TC=$IPROUTE/tc/tc 13 | IP=$IPROUTE/ip/ip 14 | IPCHAINS=/root/DS-6-beta/ipchains-1.3.9/ipchains 15 | INDEV=eth2 16 | EGDEV="dev eth1" 17 | # 18 | # tag all incoming packets from host 10.2.0.24 to value 1 19 | # tag all incoming packets from host 10.2.0.3 to value 2 20 | # tag the rest of incoming packets from subnet 10.2.0.0/24 to value 3 21 | #These values are used in the egress 22 | # 23 | ############################################################ 24 | $IPCHAINS -A input -s 10.2.0.4/24 -m 3 25 | $IPCHAINS -A input -i $INDEV -s 10.2.0.24 -m 1 26 | $IPCHAINS -A input -i $INDEV -s 10.2.0.3 -m 2 27 | 28 | ######################## Egress side ######################## 29 | 30 | 31 | # attach a dsmarker 32 | # 33 | $TC qdisc add $EGDEV handle 1:0 root dsmark indices 64 set_tc_index 34 | # 35 | # values of the DSCP to change depending on the class 36 | # 37 | #becomes EF 38 | $TC class change $EGDEV classid 1:1 dsmark mask 0x3 \ 39 | value 0xb8 40 | #becomes AF11 41 | $TC class change $EGDEV classid 1:2 dsmark mask 0x3 \ 42 | value 0x28 43 | #becomes AF21 44 | $TC class change $EGDEV classid 1:3 dsmark mask 0x3 \ 45 | value 0x48 46 | # 47 | # 48 | # The class mapping 49 | # 50 | $TC filter add $EGDEV parent 1:0 protocol ip prio 4 handle 1 fw classid 1:1 51 | $TC filter add $EGDEV parent 1:0 protocol ip prio 4 handle 2 fw classid 1:2 52 | $TC filter add $EGDEV parent 1:0 protocol ip prio 4 handle 3 fw classid 1:3 53 | # 54 | 55 | # 56 | echo "---- qdisc parameters Ingress ----------" 57 | $TC qdisc ls dev $INDEV 58 | echo "---- Class parameters Ingress ----------" 59 | $TC class ls dev $INDEV 60 | echo "---- filter parameters Ingress ----------" 61 | $TC filter ls dev $INDEV parent 1:0 62 | 63 | echo "---- qdisc parameters Egress ----------" 64 | $TC qdisc ls $EGDEV 65 | echo "---- Class parameters Egress ----------" 66 | $TC class ls $EGDEV 67 | echo "---- filter parameters Egress ----------" 68 | $TC filter ls $EGDEV parent 1:0 69 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | ROOTDIR=$(DESTDIR) 2 | PREFIX=/usr 3 | LIBDIR=$(PREFIX)/lib 4 | SBINDIR=/sbin 5 | CONFDIR=/etc/iproute2 6 | DATADIR=$(PREFIX)/share 7 | DOCDIR=$(DATADIR)/doc/iproute2 8 | MANDIR=$(DATADIR)/man 9 | ARPDDIR=/var/lib/arpd 10 | 11 | # Path to db_185.h include 12 | DBM_INCLUDE:=$(ROOTDIR)/usr/include 13 | 14 | SHARED_LIBS = y 15 | 16 | DEFINES= -DRESOLVE_HOSTNAMES -DLIBDIR=\"$(LIBDIR)\" 17 | ifneq ($(SHARED_LIBS),y) 18 | DEFINES+= -DNO_SHARED_LIBS 19 | endif 20 | 21 | DEFINES+=-DCONFDIR=\"$(CONFDIR)\" 22 | 23 | #options for decnet 24 | ADDLIB+=dnet_ntop.o dnet_pton.o 25 | 26 | #options for ipx 27 | ADDLIB+=ipx_ntop.o ipx_pton.o 28 | 29 | CC = gcc 30 | HOSTCC = gcc 31 | DEFINES += -D_GNU_SOURCE 32 | CCOPTS = -O2 33 | WFLAGS := -Wall -Wstrict-prototypes -Werror -Wmissing-prototypes 34 | WFLAGS += -Wmissing-declarations -Wold-style-definition 35 | 36 | CFLAGS = $(WFLAGS) $(CCOPTS) -I../include $(DEFINES) 37 | YACCFLAGS = -d -t -v 38 | 39 | SUBDIRS=lib ip tc bridge misc netem genl man 40 | 41 | LIBNETLINK=../lib/libnetlink.a ../lib/libutil.a 42 | LDLIBS += $(LIBNETLINK) 43 | 44 | all: Config 45 | @set -e; \ 46 | for i in $(SUBDIRS); \ 47 | do $(MAKE) $(MFLAGS) -C $$i; done 48 | 49 | Config: 50 | sh configure $(KERNEL_INCLUDE) 51 | 52 | install: all 53 | install -m 0755 -d $(DESTDIR)$(SBINDIR) 54 | install -m 0755 -d $(DESTDIR)$(CONFDIR) 55 | install -m 0755 -d $(DESTDIR)$(ARPDDIR) 56 | install -m 0755 -d $(DESTDIR)$(DOCDIR)/examples 57 | install -m 0755 -d $(DESTDIR)$(DOCDIR)/examples/diffserv 58 | install -m 0644 README.iproute2+tc $(shell find examples -maxdepth 1 -type f) \ 59 | $(DESTDIR)$(DOCDIR)/examples 60 | install -m 0644 $(shell find examples/diffserv -maxdepth 1 -type f) \ 61 | $(DESTDIR)$(DOCDIR)/examples/diffserv 62 | @for i in $(SUBDIRS) doc; do $(MAKE) -C $$i install; done 63 | install -m 0644 $(shell find etc/iproute2 -maxdepth 1 -type f) $(DESTDIR)$(CONFDIR) 64 | 65 | snapshot: 66 | echo "static const char SNAPSHOT[] = \""`date +%y%m%d`"\";" \ 67 | > include/SNAPSHOT.h 68 | 69 | clean: 70 | @for i in $(SUBDIRS) doc; \ 71 | do $(MAKE) $(MFLAGS) -C $$i clean; done 72 | 73 | clobber: 74 | touch Config 75 | $(MAKE) $(MFLAGS) clean 76 | rm -f Config cscope.* 77 | 78 | distclean: clobber 79 | 80 | cscope: 81 | cscope -b -q -R -Iinclude -sip -slib -smisc -snetem -stc 82 | 83 | .EXPORT_ALL_VARIABLES: 84 | -------------------------------------------------------------------------------- /README.lnstat: -------------------------------------------------------------------------------- 1 | lnstat - linux networking statistics 2 | (C) 2004 Harald Welte <laforge@gnumonks.org 3 | ====================================================================== 4 | 5 | This tool is a generalized and more feature-complete replacement for the old 6 | 'rtstat' program. 7 | 8 | In addition to routing cache statistics, it supports any kind of statistics 9 | the linux kernel exports via a file in /proc/net/stat. In a stock 2.6.9 10 | kernel, this is 11 | per-protocol neighbour cache statistics 12 | (ipv4, ipv6, atm, decnet) 13 | routing cache statistics 14 | (ipv4) 15 | connection tracking statistics 16 | (ipv4) 17 | 18 | Please note that lnstat will adopt to any additional statistics that might be 19 | added to the kernel at some later point 20 | 21 | I personally always like examples more than any reference documentation, so I 22 | list the following examples. If somebody wants to do a manpage, feel free 23 | to send me a patch :) 24 | 25 | EXAMPLES: 26 | 27 | In order to get a list of supported statistics files, you can run 28 | 29 | lnstat -d 30 | 31 | It will display something like 32 | 33 | /proc/net/stat/arp_cache: 34 | 1: entries 35 | 2: allocs 36 | 3: destroys 37 | [...] 38 | /proc/net/stat/rt_cache: 39 | 1: entries 40 | 2: in_hit 41 | 3: in_slow_tot 42 | 43 | You can now select the files/keys you are interested by something like 44 | 45 | lnstat -k arp_cache:entries,rt_cache:in_hit,arp_cache:destroys 46 | 47 | arp_cach|rt_cache|arp_cach| 48 | entries| in_hit|destroys| 49 | 6| 6| 0| 50 | 6| 0| 0| 51 | 6| 2| 0| 52 | 53 | 54 | You can specify the interval (e.g. 10 seconds) by: 55 | 56 | lnstat -i 10 57 | 58 | You can specify to only use one particular statistics file: 59 | 60 | lnstat -f ip_conntrack 61 | 62 | You can specify individual field widths 63 | 64 | lnstat -k arp_cache:entries,rt_cache:entries -w 20,8 65 | 66 | You can specify not to print a header at all 67 | 68 | lnstat -s 0 69 | 70 | You can specify to print a header only at start of the program 71 | 72 | lnstat -s 1 73 | 74 | You can specify to print a header at start and every 20 lines: 75 | 76 | lnstat -s 20 77 | 78 | You can specify the number of samples you want to take (e.g. 5): 79 | 80 | lnstat -c 5 81 | 82 | -------------------------------------------------------------------------------- /man/man8/ip-ntable.8: -------------------------------------------------------------------------------- 1 | .TH IP\-NTABLE 8 "20 Dec 2011" "iproute2" "Linux" 2 | .SH "NAME" 3 | ip-ntable - neighbour table configuration 4 | .SH "SYNOPSIS" 5 | .sp 6 | .ad l 7 | .in +8 8 | .ti -8 9 | .B ip 10 | .RI "[ " OPTIONS " ]" 11 | .B address 12 | .RI " { " COMMAND " | " 13 | .BR help " }" 14 | .sp 15 | 16 | .ti -8 17 | .BR "ip ntable change name" 18 | .IR NAME " [ " 19 | .B dev 20 | .IR DEV " ] " PARMS 21 | 22 | .ti -8 23 | .IR PARMS " := { " 24 | .B thresh1 25 | .IR VAL " | " 26 | .B thresh2 27 | .IR VAL " | " 28 | .B thresh3 29 | .IR VAL " | " 30 | .B gc_int 31 | .IR MSEC " | " 32 | .B base_reachable 33 | .IR MSEC " | " 34 | .B retrans 35 | .IR MSEC " | " "gc_stale MSEC " " | " 36 | .B delay_probe 37 | .IR MSEC " | " "queue LEN " " | " 38 | .B app_probs 39 | .IR VAL " | " 40 | .B ucast_probes 41 | .IR VAL " | " "mcast_probes VAL " " | " 42 | .B anycast_delay 43 | .IR MSEC " | " 44 | .B proxy_delay 45 | .IR MSEC " | " "proxy_queue LEN " " | " 46 | .B locktime 47 | .IR MSEC " }" 48 | 49 | .ti -8 50 | .BR "ip ntable show" " [ " 51 | .B dev 52 | .IR DEV " ] [ " 53 | .B name 54 | .IR NAME " ]" 55 | 56 | .SH DESCRIPTION 57 | .I ip ntable 58 | controls the parameters for the neighbour tables. 59 | 60 | .SS ip ntable show - list the ip neighbour tables 61 | 62 | This commands displays neighbour table parameters and statistics. 63 | 64 | .TP 65 | .BI dev " DEV" 66 | only list the table attached to this device. 67 | 68 | .TP 69 | .BI name " NAME" 70 | only lists the table with the given name. 71 | 72 | .SS ip ntable change - modify table parameter 73 | 74 | This command allows modifying table parameters such as timers and queue lengths. 75 | .TP 76 | .BI name " NAME" 77 | the name of the table to modify. 78 | 79 | .TP 80 | .BI dev " DEV" 81 | the name of the device to modify the table values. 82 | 83 | .SH EXAMPLES 84 | .PP 85 | ip ntable show dev eth0 86 | .RS 4 87 | Shows the neighbour table (IPv4 ARP and IPv6 ndisc) parameters on device eth0. 88 | .RE 89 | .PP 90 | ip ntable change name arp_cache queue 8 dev eth0 91 | .RS 4 92 | Changes the number of packets queued while address is being resolved from the 93 | default value (3) to 8 packets. 94 | .RE 95 | 96 | .SH SEE ALSO 97 | .br 98 | .BR ip (8) 99 | 100 | .SH AUTHOR 101 | Manpage by Stephen Hemminger 102 | -------------------------------------------------------------------------------- /tc/m_pedit.h: -------------------------------------------------------------------------------- 1 | /* 2 | * m_pedit.h generic packet editor actions module 3 | * 4 | * This program is free software; you can distribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: J Hadi Salim (hadi@cyberus.ca) 10 | * 11 | */ 12 | 13 | #ifndef _ACT_PEDIT_H_ 14 | #define _ACT_PEDIT_H_ 1 15 | 16 | #include <stdio.h> 17 | #include <stdlib.h> 18 | #include <unistd.h> 19 | #include <syslog.h> 20 | #include <fcntl.h> 21 | #include <sys/socket.h> 22 | #include <netinet/in.h> 23 | #include <arpa/inet.h> 24 | #include <string.h> 25 | #include "utils.h" 26 | #include "tc_util.h" 27 | #include <linux/tc_act/tc_pedit.h> 28 | 29 | #define MAX_OFFS 128 30 | 31 | #define TIPV4 1 32 | #define TIPV6 2 33 | #define TINT 3 34 | #define TU32 4 35 | 36 | #define RU32 0xFFFFFFFF 37 | #define RU16 0xFFFF 38 | #define RU8 0xFF 39 | 40 | #define PEDITKINDSIZ 16 41 | 42 | struct m_pedit_util 43 | { 44 | struct m_pedit_util *next; 45 | char id[PEDITKINDSIZ]; 46 | int (*parse_peopt)(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey); 47 | }; 48 | 49 | 50 | extern int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey); 51 | extern int pack_key(struct tc_pedit_sel *sel,struct tc_pedit_key *tkey); 52 | extern int pack_key32(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey); 53 | extern int pack_key16(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey); 54 | extern int pack_key8(__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey); 55 | extern int parse_val(int *argc_p, char ***argv_p, __u32 * val, int type); 56 | extern int parse_cmd(int *argc_p, char ***argv_p, __u32 len, int type,__u32 retain,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey); 57 | extern int parse_offset(int *argc_p, char ***argv_p,struct tc_pedit_sel *sel,struct tc_pedit_key *tkey); 58 | int parse_pedit(struct action_util *a, int *argc_p, char ***argv_p, int tca_id, struct nlmsghdr *n); 59 | extern int print_pedit(struct action_util *au,FILE * f, struct rtattr *arg); 60 | extern int pedit_print_xstats(struct action_util *au, FILE *f, struct rtattr *xstats); 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /man/man8/tc-hfsc.8: -------------------------------------------------------------------------------- 1 | .TH HFSC 8 "31 October 2011" iproute2 Linux 2 | . 3 | .SH NAME 4 | HFSC \- Hierarchical Fair Service Curve's control under linux 5 | . 6 | .SH SYNOPSIS 7 | .nf 8 | tc qdisc add ... hfsc [ \fBdefault\fR CLASSID ] 9 | 10 | tc class add ... hfsc [ [ \fBrt\fR SC ] [ \fBls\fR SC ] | [ \fBsc\fR SC ] ] [ \fBul\fR SC ] 11 | 12 | \fBrt\fR : realtime service curve 13 | \fBls\fR : linkshare service curve 14 | \fBsc\fR : rt+ls service curve 15 | \fBul\fR : upperlimit service curve 16 | 17 | \(bu at least one of \fBrt\fR, \fBls\fR or \fBsc\fR must be specified 18 | \(bu \fBul\fR can only be specified with \fBls\fR or \fBsc\fR 19 | . 20 | .IP "SC := [ [ \fBm1\fR BPS ] \fBd\fR SEC ] \fBm2\fR BPS" 21 | \fBm1\fR : slope of the first segment 22 | \fBd\fR : x\-coordinate of intersection 23 | \fBm2\fR : slope of the second segment 24 | .PP 25 | .IP "SC := [ [ \fBumax\fR BYTE ] \fBdmax\fR SEC ] \fBrate\fR BPS" 26 | \fBumax\fR : maximum unit of work 27 | \fBdmax\fR : maximum delay 28 | \fBrate\fR : rate 29 | .PP 30 | .fi 31 | For description of BYTE, BPS and SEC \- please see \fBUNITS\fR 32 | section of \fBtc\fR(8). 33 | . 34 | .SH DESCRIPTION (qdisc) 35 | HFSC qdisc has only one optional parameter \- \fBdefault\fR. CLASSID specifies 36 | the minor part of the default classid, where packets not classified by other 37 | means (e.g. u32 filter, CLASSIFY target of iptables) will be enqueued. If 38 | \fBdefault\fR is not specified, unclassified packets will be dropped. 39 | . 40 | .SH DESCRIPTION (class) 41 | HFSC class is used to create a class hierarchy for HFSC scheduler. For 42 | explanation of the algorithm, and the meaning behind \fBrt\fR, \fBls\fR, 43 | \fBsc\fR and \fBul\fR service curves \- please refer to \fBtc\-hfsc\fR(7). 44 | 45 | As you can see in \fBSYNOPSIS\fR, service curve (SC) can be specified in two 46 | ways. Either as maximum delay for certain amount of work, or as a bandwidth 47 | assigned for certain amount of time. Obviously, \fBm1\fR is simply 48 | \fBumax\fR/\fBdmax\fR. 49 | 50 | Both \fBm2\fR and \fBrate\fR are mandatory. If you omit other 51 | parameters, you will specify linear service curve. 52 | . 53 | .SH "SEE ALSO" 54 | . 55 | \fBtc\fR(8), \fBtc\-hfsc\fR(7), \fBtc\-stab\fR(8) 56 | 57 | Please direct bugreports and patches to: <net...@vger.kernel.org> 58 | . 59 | .SH "AUTHOR" 60 | . 61 | Manpage created by Michal Soltys (sol...@ziu.info) 62 | -------------------------------------------------------------------------------- /man/man8/lnstat.8: -------------------------------------------------------------------------------- 1 | .TH LNSTAT 8 2 | .SH NAME 3 | lnstat \- unified linux network statistics 4 | .SH SYNOPSIS 5 | .B lnstat 6 | .RI [ options ] 7 | .SH DESCRIPTION 8 | This manual page documents briefly the 9 | .B lnstat 10 | command. 11 | .PP 12 | \fBlnstat\fP is a generalized and more feature-complete replacement for the old rtstat program. 13 | In addition to routing cache statistics, it supports any kind of statistics the linux kernel 14 | exports via a file in /proc/net/stat/. 15 | .SH OPTIONS 16 | These programs follow the usual GNU command line syntax, with long 17 | options starting with two dashes (`-'). 18 | lnstat supports the following options. 19 | .TP 20 | .B \-h, \-\-help 21 | Show summary of options. 22 | .TP 23 | .B \-V, \-\-version 24 | Show version of program. 25 | .TP 26 | .B \-c, \-\-count <count> 27 | Print <count> number of intervals. 28 | .TP 29 | .B \-d, \-\-dump 30 | Dump list of available files/keys. 31 | .TP 32 | .B \-f, \-\-file <file> 33 | Statistics file to use. 34 | .TP 35 | .B \-i, \-\-interval <intv> 36 | Set interval to 'intv' seconds. 37 | .TP 38 | .B \-k, \-\-keys k,k,k,... 39 | Display only keys specified. 40 | .TP 41 | .B \-s, \-\-subject [0-2] 42 | Specify display of subject/header. '0' means no header at all, '1' prints a header only at start of the program and '2' prints a header every 20 lines. 43 | .TP 44 | .B \-w, \-\-width n,n,n,... 45 | Width for each field. 46 | .SH USAGE EXAMPLES 47 | .TP 48 | .B # lnstat -d 49 | Get a list of supported statistics files. 50 | .TP 51 | .B # lnstat -k arp_cache:entries,rt_cache:in_hit,arp_cache:destroys 52 | Select the specified files and keys. 53 | .TP 54 | .B # lnstat -i 10 55 | Use an interval of 10 seconds. 56 | .TP 57 | .B # lnstat -f ip_conntrack 58 | Use only the specified file for statistics. 59 | .TP 60 | .B # lnstat -s 0 61 | Do not print a header at all. 62 | .TP 63 | .B # lnstat -s 20 64 | Print a header at start and every 20 lines. 65 | .TP 66 | .B # lnstat -c -1 -i 1 -f rt_cache -k entries,in_hit,in_slow_tot 67 | Display statistics for keys entries, in_hit and in_slow_tot of field rt_cache every second. 68 | .SH SEE ALSO 69 | .BR ip (8), 70 | and /usr/share/doc/iproute-doc/README.lnstat (package iproute-doc on Debian) 71 | .br 72 | .SH AUTHOR 73 | lnstat was written by Harald Welte <laforge@gnumonks.org>. 74 | .PP 75 | This manual page was written by Michael Prokop <mika@grml.org> for the Debian project (but may be used by others). 76 | -------------------------------------------------------------------------------- /tc/q_multiq.c: -------------------------------------------------------------------------------- 1 | /* 2 | * q_multiq.c Multiqueue aware qdisc 3 | * 4 | * Copyright (c) 2008, Intel Corporation. 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms and conditions of the GNU General Public License, 8 | * version 2, as published by the Free Software Foundation. 9 | * 10 | * This program is distributed in the hope it will be useful, but WITHOUT 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 13 | * more details. 14 | * 15 | * You should have received a copy of the GNU General Public License along with 16 | * this program; if not, write to the Free Software Foundation, Inc., 59 Temple 17 | * Place - Suite 330, Boston, MA 02111-1307 USA. 18 | * 19 | * Author: Alexander Duyck <alexander.h.duyck@intel.com> 20 | * 21 | * Original Authors: PJ Waskiewicz, <peter.p.waskiewicz.jr@intel.com> (RR) 22 | * Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> (from PRIO) 23 | * 24 | */ 25 | 26 | #include <stdio.h> 27 | #include <stdlib.h> 28 | #include <unistd.h> 29 | #include <syslog.h> 30 | #include <fcntl.h> 31 | #include <sys/socket.h> 32 | #include <netinet/in.h> 33 | #include <arpa/inet.h> 34 | #include <string.h> 35 | 36 | #include "utils.h" 37 | #include "tc_util.h" 38 | 39 | static void explain(void) 40 | { 41 | fprintf(stderr, "Usage: ... multiq [help]\n"); 42 | } 43 | 44 | static int multiq_parse_opt(struct qdisc_util *qu, int argc, char **argv, 45 | struct nlmsghdr *n) 46 | { 47 | struct tc_multiq_qopt opt; 48 | 49 | if (argc) { 50 | if (strcmp(*argv, "help") == 0) { 51 | explain(); 52 | return -1; 53 | } else { 54 | fprintf(stderr, "What is \"%s\"?\n", *argv); 55 | explain(); 56 | return -1; 57 | } 58 | } 59 | 60 | addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); 61 | return 0; 62 | } 63 | 64 | static int multiq_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) 65 | { 66 | struct tc_multiq_qopt *qopt; 67 | 68 | if (opt == NULL) 69 | return 0; 70 | if (RTA_PAYLOAD(opt) < sizeof(*qopt)) 71 | return 0; 72 | 73 | qopt = RTA_DATA(opt); 74 | 75 | fprintf(f, "bands %u/%u ", qopt->bands, qopt->max_bands); 76 | 77 | return 0; 78 | } 79 | 80 | struct qdisc_util multiq_qdisc_util = { 81 | .id = "multiq", 82 | .parse_qopt = multiq_parse_opt, 83 | .print_qopt = multiq_print_opt, 84 | }; 85 | -------------------------------------------------------------------------------- /include/linux/netfilter_ipv4.h: -------------------------------------------------------------------------------- 1 | /* IPv4-specific defines for netfilter. 2 | * (C)1998 Rusty Russell -- This code is GPL. 3 | */ 4 | #ifndef __LINUX_IP_NETFILTER_H 5 | #define __LINUX_IP_NETFILTER_H 6 | 7 | 8 | #include <linux/netfilter.h> 9 | 10 | /* only for userspace compatibility */ 11 | 12 | #include <limits.h> /* for INT_MIN, INT_MAX */ 13 | 14 | /* IP Cache bits. */ 15 | /* Src IP address. */ 16 | #define NFC_IP_SRC 0x0001 17 | /* Dest IP address. */ 18 | #define NFC_IP_DST 0x0002 19 | /* Input device. */ 20 | #define NFC_IP_IF_IN 0x0004 21 | /* Output device. */ 22 | #define NFC_IP_IF_OUT 0x0008 23 | /* TOS. */ 24 | #define NFC_IP_TOS 0x0010 25 | /* Protocol. */ 26 | #define NFC_IP_PROTO 0x0020 27 | /* IP options. */ 28 | #define NFC_IP_OPTIONS 0x0040 29 | /* Frag & flags. */ 30 | #define NFC_IP_FRAG 0x0080 31 | 32 | /* Per-protocol information: only matters if proto match. */ 33 | /* TCP flags. */ 34 | #define NFC_IP_TCPFLAGS 0x0100 35 | /* Source port. */ 36 | #define NFC_IP_SRC_PT 0x0200 37 | /* Dest port. */ 38 | #define NFC_IP_DST_PT 0x0400 39 | /* Something else about the proto */ 40 | #define NFC_IP_PROTO_UNKNOWN 0x2000 41 | 42 | /* IP Hooks */ 43 | /* After promisc drops, checksum checks. */ 44 | #define NF_IP_PRE_ROUTING 0 45 | /* If the packet is destined for this box. */ 46 | #define NF_IP_LOCAL_IN 1 47 | /* If the packet is destined for another interface. */ 48 | #define NF_IP_FORWARD 2 49 | /* Packets coming from a local process. */ 50 | #define NF_IP_LOCAL_OUT 3 51 | /* Packets about to hit the wire. */ 52 | #define NF_IP_POST_ROUTING 4 53 | #define NF_IP_NUMHOOKS 5 54 | 55 | enum nf_ip_hook_priorities { 56 | NF_IP_PRI_FIRST = INT_MIN, 57 | NF_IP_PRI_CONNTRACK_DEFRAG = -400, 58 | NF_IP_PRI_RAW = -300, 59 | NF_IP_PRI_SELINUX_FIRST = -225, 60 | NF_IP_PRI_CONNTRACK = -200, 61 | NF_IP_PRI_MANGLE = -150, 62 | NF_IP_PRI_NAT_DST = -100, 63 | NF_IP_PRI_FILTER = 0, 64 | NF_IP_PRI_SECURITY = 50, 65 | NF_IP_PRI_NAT_SRC = 100, 66 | NF_IP_PRI_SELINUX_LAST = 225, 67 | NF_IP_PRI_CONNTRACK_HELPER = 300, 68 | NF_IP_PRI_CONNTRACK_CONFIRM = INT_MAX, 69 | NF_IP_PRI_LAST = INT_MAX, 70 | }; 71 | 72 | /* Arguments for setsockopt SOL_IP: */ 73 | /* 2.0 firewalling went from 64 through 71 (and +256, +512, etc). */ 74 | /* 2.2 firewalling (+ masq) went from 64 through 76 */ 75 | /* 2.4 firewalling went 64 through 67. */ 76 | #define SO_ORIGINAL_DST 80 77 | 78 | 79 | #endif /* __LINUX_IP_NETFILTER_H */ 80 | -------------------------------------------------------------------------------- /include/linux/tc_ematch/tc_em_meta.h: -------------------------------------------------------------------------------- 1 | #ifndef __LINUX_TC_EM_META_H 2 | #define __LINUX_TC_EM_META_H 3 | 4 | #include <linux/types.h> 5 | #include <linux/pkt_cls.h> 6 | 7 | enum { 8 | TCA_EM_META_UNSPEC, 9 | TCA_EM_META_HDR, 10 | TCA_EM_META_LVALUE, 11 | TCA_EM_META_RVALUE, 12 | __TCA_EM_META_MAX 13 | }; 14 | #define TCA_EM_META_MAX (__TCA_EM_META_MAX - 1) 15 | 16 | struct tcf_meta_val { 17 | __u16 kind; 18 | __u8 shift; 19 | __u8 op; 20 | }; 21 | 22 | #define TCF_META_TYPE_MASK (0xf << 12) 23 | #define TCF_META_TYPE(kind) (((kind) & TCF_META_TYPE_MASK) >> 12) 24 | #define TCF_META_ID_MASK 0x7ff 25 | #define TCF_META_ID(kind) ((kind) & TCF_META_ID_MASK) 26 | 27 | enum { 28 | TCF_META_TYPE_VAR, 29 | TCF_META_TYPE_INT, 30 | __TCF_META_TYPE_MAX 31 | }; 32 | #define TCF_META_TYPE_MAX (__TCF_META_TYPE_MAX - 1) 33 | 34 | enum { 35 | TCF_META_ID_VALUE, 36 | TCF_META_ID_RANDOM, 37 | TCF_META_ID_LOADAVG_0, 38 | TCF_META_ID_LOADAVG_1, 39 | TCF_META_ID_LOADAVG_2, 40 | TCF_META_ID_DEV, 41 | TCF_META_ID_PRIORITY, 42 | TCF_META_ID_PROTOCOL, 43 | TCF_META_ID_PKTTYPE, 44 | TCF_META_ID_PKTLEN, 45 | TCF_META_ID_DATALEN, 46 | TCF_META_ID_MACLEN, 47 | TCF_META_ID_NFMARK, 48 | TCF_META_ID_TCINDEX, 49 | TCF_META_ID_RTCLASSID, 50 | TCF_META_ID_RTIIF, 51 | TCF_META_ID_SK_FAMILY, 52 | TCF_META_ID_SK_STATE, 53 | TCF_META_ID_SK_REUSE, 54 | TCF_META_ID_SK_BOUND_IF, 55 | TCF_META_ID_SK_REFCNT, 56 | TCF_META_ID_SK_SHUTDOWN, 57 | TCF_META_ID_SK_PROTO, 58 | TCF_META_ID_SK_TYPE, 59 | TCF_META_ID_SK_RCVBUF, 60 | TCF_META_ID_SK_RMEM_ALLOC, 61 | TCF_META_ID_SK_WMEM_ALLOC, 62 | TCF_META_ID_SK_OMEM_ALLOC, 63 | TCF_META_ID_SK_WMEM_QUEUED, 64 | TCF_META_ID_SK_RCV_QLEN, 65 | TCF_META_ID_SK_SND_QLEN, 66 | TCF_META_ID_SK_ERR_QLEN, 67 | TCF_META_ID_SK_FORWARD_ALLOCS, 68 | TCF_META_ID_SK_SNDBUF, 69 | TCF_META_ID_SK_ALLOCS, 70 | __TCF_META_ID_SK_ROUTE_CAPS, /* unimplemented but in ABI already */ 71 | TCF_META_ID_SK_HASH, 72 | TCF_META_ID_SK_LINGERTIME, 73 | TCF_META_ID_SK_ACK_BACKLOG, 74 | TCF_META_ID_SK_MAX_ACK_BACKLOG, 75 | TCF_META_ID_SK_PRIO, 76 | TCF_META_ID_SK_RCVLOWAT, 77 | TCF_META_ID_SK_RCVTIMEO, 78 | TCF_META_ID_SK_SNDTIMEO, 79 | TCF_META_ID_SK_SENDMSG_OFF, 80 | TCF_META_ID_SK_WRITE_PENDING, 81 | TCF_META_ID_VLAN_TAG, 82 | TCF_META_ID_RXHASH, 83 | __TCF_META_ID_MAX 84 | }; 85 | #define TCF_META_ID_MAX (__TCF_META_ID_MAX - 1) 86 | 87 | struct tcf_meta_hdr { 88 | struct tcf_meta_val left; 89 | struct tcf_meta_val right; 90 | }; 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /man/man8/tc-bfifo.8: -------------------------------------------------------------------------------- 1 | .TH PBFIFO 8 "10 January 2002" "iproute2" "Linux" 2 | .SH NAME 3 | pfifo \- Packet limited First In, First Out queue 4 | .P 5 | bfifo \- Byte limited First In, First Out queue 6 | 7 | .SH SYNOPSIS 8 | .B tc qdisc ... add pfifo 9 | .B [ limit 10 | packets 11 | .B ] 12 | .P 13 | .B tc qdisc ... add bfifo 14 | .B [ limit 15 | bytes 16 | .B ] 17 | 18 | .SH DESCRIPTION 19 | The pfifo and bfifo qdiscs are unadorned First In, First Out queues. They are the 20 | simplest queues possible and therefore have no overhead. 21 | .B pfifo 22 | constrains the queue size as measured in packets. 23 | .B bfifo 24 | does so as measured in bytes. 25 | 26 | Like all non-default qdiscs, they maintain statistics. This might be a reason to prefer 27 | pfifo or bfifo over the default. 28 | 29 | .SH ALGORITHM 30 | A list of packets is maintained, when a packet is enqueued it gets inserted at the tail of 31 | a list. When a packet needs to be sent out to the network, it is taken from the head of the list. 32 | 33 | If the list is too long, no further packets are allowed on. This is called 'tail drop'. 34 | 35 | .SH PARAMETERS 36 | .TP 37 | limit 38 | Maximum queue size. Specified in bytes for bfifo, in packets for pfifo. For pfifo, defaults 39 | to the interface txqueuelen, as specified with 40 | .BR ifconfig (8) 41 | or 42 | .BR ip (8). 43 | The range for this parameter is [0, UINT32_MAX]. 44 | 45 | For bfifo, it defaults to the txqueuelen multiplied by the interface MTU. 46 | The range for this parameter is [0, UINT32_MAX] bytes. 47 | 48 | Note: The link layer header was considered when counting packets length. 49 | 50 | .SH OUTPUT 51 | The output of 52 | .B tc -s qdisc ls 53 | contains the limit, either in packets or in bytes, and the number of bytes 54 | and packets actually sent. An unsent and dropped packet only appears between braces 55 | and is not counted as 'Sent'. 56 | 57 | In this example, the queue length is 100 packets, 45894 bytes were sent over 681 packets. 58 | No packets were dropped, and as the pfifo queue does not slow down packets, there were also no 59 | overlimits: 60 | .P 61 | .nf 62 | # tc -s qdisc ls dev eth0 63 | qdisc pfifo 8001: dev eth0 limit 100p 64 | Sent 45894 bytes 681 pkts (dropped 0, overlimits 0) 65 | .fi 66 | 67 | If a backlog occurs, this is displayed as well. 68 | .SH SEE ALSO 69 | .BR tc (8) 70 | 71 | .SH AUTHORS 72 | Alexey N. Kuznetsov, <kuznet@ms2.inr.ac.ru> 73 | 74 | This manpage maintained by bert hubert <ahu@ds9a.nl> 75 | 76 | 77 | -------------------------------------------------------------------------------- /lib/ll_addr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ll_addr.c 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 | */ 11 | 12 | #include <stdio.h> 13 | #include <stdlib.h> 14 | #include <unistd.h> 15 | #include <syslog.h> 16 | #include <fcntl.h> 17 | #include <sys/ioctl.h> 18 | #include <sys/socket.h> 19 | #include <sys/ioctl.h> 20 | #include <netinet/in.h> 21 | #include <arpa/inet.h> 22 | #include <string.h> 23 | 24 | #include <linux/netdevice.h> 25 | #include <linux/if_arp.h> 26 | #include <linux/sockios.h> 27 | 28 | #include "rt_names.h" 29 | #include "utils.h" 30 | 31 | 32 | const char *ll_addr_n2a(unsigned char *addr, int alen, int type, char *buf, int blen) 33 | { 34 | int i; 35 | int l; 36 | 37 | if (alen == 4 && 38 | (type == ARPHRD_TUNNEL || type == ARPHRD_SIT || type == ARPHRD_IPGRE)) { 39 | return inet_ntop(AF_INET, addr, buf, blen); 40 | } 41 | if (alen == 16 && type == ARPHRD_TUNNEL6) { 42 | return inet_ntop(AF_INET6, addr, buf, blen); 43 | } 44 | l = 0; 45 | for (i=0; i<alen; i++) { 46 | if (i==0) { 47 | snprintf(buf+l, blen, "%02x", addr[i]); 48 | blen -= 2; 49 | l += 2; 50 | } else { 51 | snprintf(buf+l, blen, ":%02x", addr[i]); 52 | blen -= 3; 53 | l += 3; 54 | } 55 | } 56 | return buf; 57 | } 58 | 59 | /*NB: lladdr is char * (rather than u8 *) because sa_data is char * (1003.1g) */ 60 | int ll_addr_a2n(char *lladdr, int len, const char *arg) 61 | { 62 | if (strchr(arg, '.')) { 63 | inet_prefix pfx; 64 | if (get_addr_1(&pfx, arg, AF_INET)) { 65 | fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg); 66 | return -1; 67 | } 68 | if (len < 4) 69 | return -1; 70 | memcpy(lladdr, pfx.data, 4); 71 | return 4; 72 | } else { 73 | int i; 74 | 75 | for (i=0; i<len; i++) { 76 | int temp; 77 | char *cp = strchr(arg, ':'); 78 | if (cp) { 79 | *cp = 0; 80 | cp++; 81 | } 82 | if (sscanf(arg, "%x", &temp) != 1) { 83 | fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg); 84 | return -1; 85 | } 86 | if (temp < 0 || temp > 255) { 87 | fprintf(stderr, "\"%s\" is invalid lladdr.\n", arg); 88 | return -1; 89 | } 90 | lladdr[i] = temp; 91 | if (!cp) 92 | break; 93 | arg = cp; 94 | } 95 | return i+1; 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /ip/iplink_macvtap.c: -------------------------------------------------------------------------------- 1 | /* 2 | * iplink_macvtap.c macvtap device support 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | */ 9 | 10 | #include <stdio.h> 11 | #include <stdlib.h> 12 | #include <string.h> 13 | #include <sys/socket.h> 14 | #include <linux/if_link.h> 15 | 16 | #include "rt_names.h" 17 | #include "utils.h" 18 | #include "ip_common.h" 19 | 20 | static void explain(void) 21 | { 22 | fprintf(stderr, 23 | "Usage: ... macvtap mode { private | vepa | bridge | passthru }\n" 24 | ); 25 | } 26 | 27 | static int mode_arg(const char *arg) 28 | { 29 | fprintf(stderr, "Error: argument of \"mode\" must be \"private\", " 30 | "\"vepa\", \"bridge\" or \"passthru\", not \"%s\"\n", arg); 31 | return -1; 32 | } 33 | 34 | static int macvtap_parse_opt(struct link_util *lu, int argc, char **argv, 35 | struct nlmsghdr *n) 36 | { 37 | while (argc > 0) { 38 | if (matches(*argv, "mode") == 0) { 39 | __u32 mode = 0; 40 | NEXT_ARG(); 41 | 42 | if (strcmp(*argv, "private") == 0) 43 | mode = MACVLAN_MODE_PRIVATE; 44 | else if (strcmp(*argv, "vepa") == 0) 45 | mode = MACVLAN_MODE_VEPA; 46 | else if (strcmp(*argv, "bridge") == 0) 47 | mode = MACVLAN_MODE_BRIDGE; 48 | else if (strcmp(*argv, "passthru") == 0) 49 | mode = MACVLAN_MODE_PASSTHRU; 50 | else 51 | return mode_arg(*argv); 52 | 53 | addattr32(n, 1024, IFLA_MACVLAN_MODE, mode); 54 | } else if (matches(*argv, "help") == 0) { 55 | explain(); 56 | return -1; 57 | } else { 58 | fprintf(stderr, "macvtap: unknown command \"%s\"?\n", *argv); 59 | explain(); 60 | return -1; 61 | } 62 | argc--, argv++; 63 | } 64 | 65 | return 0; 66 | } 67 | 68 | static void macvtap_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) 69 | { 70 | __u32 mode; 71 | 72 | if (!tb) 73 | return; 74 | 75 | if (!tb[IFLA_MACVLAN_MODE] || 76 | RTA_PAYLOAD(tb[IFLA_MACVLAN_MODE]) < sizeof(__u32)) 77 | return; 78 | 79 | mode = rta_getattr_u32(tb[IFLA_VLAN_ID]); 80 | fprintf(f, " mode %s ", 81 | mode == MACVLAN_MODE_PRIVATE ? "private" 82 | : mode == MACVLAN_MODE_VEPA ? "vepa" 83 | : mode == MACVLAN_MODE_BRIDGE ? "bridge" 84 | : mode == MACVLAN_MODE_PASSTHRU ? "passthru" 85 | : "unknown"); 86 | } 87 | 88 | struct link_util macvtap_link_util = { 89 | .id = "macvtap", 90 | .maxattr = IFLA_MACVLAN_MAX, 91 | .parse_opt = macvtap_parse_opt, 92 | .print_opt = macvtap_print_opt, 93 | }; 94 | -------------------------------------------------------------------------------- /tc/m_ematch.h: -------------------------------------------------------------------------------- 1 | #ifndef __TC_EMATCH_H_ 2 | #define __TC_EMATCH_H_ 3 | 4 | #include <ctype.h> 5 | #include <stdlib.h> 6 | #include <string.h> 7 | #include <limits.h> 8 | 9 | #include "utils.h" 10 | #include "tc_util.h" 11 | 12 | #define EMATCHKINDSIZ 16 13 | 14 | struct bstr 15 | { 16 | char *data; 17 | unsigned int len; 18 | int quoted; 19 | struct bstr *next; 20 | }; 21 | 22 | extern struct bstr * bstr_alloc(const char *text); 23 | 24 | static inline struct bstr * bstr_new(char *data, unsigned int len) 25 | { 26 | struct bstr *b = calloc(1, sizeof(*b)); 27 | 28 | if (b == NULL) 29 | return NULL; 30 | 31 | b->data = data; 32 | b->len = len; 33 | 34 | return b; 35 | } 36 | 37 | static inline int bstrcmp(struct bstr *b, const char *text) 38 | { 39 | int len = strlen(text); 40 | int d = b->len - len; 41 | 42 | if (d == 0) 43 | return strncmp(b->data, text, len); 44 | 45 | return d; 46 | } 47 | 48 | static inline struct bstr *bstr_next(struct bstr *b) 49 | { 50 | return b->next; 51 | } 52 | 53 | extern unsigned long bstrtoul(const struct bstr *b); 54 | extern void bstr_print(FILE *fd, const struct bstr *b, int ascii); 55 | 56 | 57 | struct ematch 58 | { 59 | struct bstr *args; 60 | int index; 61 | int inverted; 62 | int relation; 63 | int child_ref; 64 | struct ematch *child; 65 | struct ematch *next; 66 | }; 67 | 68 | static inline struct ematch * new_ematch(struct bstr *args, int inverted) 69 | { 70 | struct ematch *e = calloc(1, sizeof(*e)); 71 | 72 | if (e == NULL) 73 | return NULL; 74 | 75 | e->args = args; 76 | e->inverted = inverted; 77 | 78 | return e; 79 | } 80 | 81 | extern void print_ematch_tree(const struct ematch *tree); 82 | 83 | 84 | struct ematch_util 85 | { 86 | char kind[EMATCHKINDSIZ]; 87 | int kind_num; 88 | int (*parse_eopt)(struct nlmsghdr *,struct tcf_ematch_hdr *, 89 | struct bstr *); 90 | int (*print_eopt)(FILE *, struct tcf_ematch_hdr *, void *, int); 91 | void (*print_usage)(FILE *); 92 | struct ematch_util *next; 93 | }; 94 | 95 | static inline int parse_layer(struct bstr *b) 96 | { 97 | if (*((char *) b->data) == 'l') 98 | return TCF_LAYER_LINK; 99 | else if (*((char *) b->data) == 'n') 100 | return TCF_LAYER_NETWORK; 101 | else if (*((char *) b->data) == 't') 102 | return TCF_LAYER_TRANSPORT; 103 | else 104 | return INT_MAX; 105 | } 106 | 107 | extern int em_parse_error(int err, struct bstr *args, struct bstr *carg, 108 | struct ematch_util *, char *fmt, ...); 109 | extern int print_ematch(FILE *, const struct rtattr *); 110 | extern int parse_ematch(int *, char ***, int, struct nlmsghdr *); 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /examples/diffserv/README: -------------------------------------------------------------------------------- 1 | 2 | Note all these are mere examples which can be customized to your needs 3 | 4 | AFCBQ 5 | ----- 6 | AF PHB built using CBQ, DSMARK,GRED (default in GRIO mode) ,RED for BE 7 | and the tcindex classifier with some algorithmic mapping 8 | 9 | EFCBQ 10 | ----- 11 | EF PHB built using CBQ (for rate control and prioritization), 12 | DSMARK( to remark DSCPs), tcindex classifier and RED for the BE 13 | traffic. 14 | 15 | EFPRIO 16 | ------ 17 | EF PHB using the PRIO scheduler, Token Bucket to rate control EF, 18 | tcindex classifier, DSMARK to remark, and RED for the BE traffic 19 | 20 | EDGE scripts 21 | ============== 22 | 23 | CB-3(1|2)-(u32/chains) 24 | ====================== 25 | 26 | 27 | The major differences are that the classifier is u32 on -u32 extension 28 | and IPchains on the chains extension. CB stands for color Blind 29 | and 31 is for the mode where only a CIR and CBS are defined whereas 30 | 32 stands for a mode where a CIR/CBS + PIR/EBS are defined. 31 | 32 | Color Blind (CB) 33 | ==========-----= 34 | We look at one special subnet that we are interested in for simplicty 35 | reasons to demonstrate the capability. We send the packets from that 36 | subnet to AF4*, BE or end up dropping depending on the metering results. 37 | 38 | 39 | The algorithm overview is as follows: 40 | 41 | *classify: 42 | 43 | **case: subnet X 44 | ---------------- 45 | if !exceed meter1 tag as AF41 46 | else 47 | if !exceed meter2 tag as AF42 48 | else 49 | if !exceed meter 3 tag as AF43 50 | else 51 | drop 52 | 53 | default case: Any other subnet 54 | ------------------------------- 55 | if !exceed meter 5 tag as AF43 56 | else 57 | drop 58 | 59 | 60 | One Egress side change the DSCPs of the packets to reflect AF4* and BE 61 | based on the tags from the ingress. 62 | 63 | ------------------------------------------------------------- 64 | 65 | Color Aware 66 | =========== 67 | 68 | Define some meters with + policing and give them IDs eg 69 | 70 | meter1=police index 1 rate $CIR1 burst $CBS1 71 | meter2=police index 2 rate $CIR2 burst $CBS2 etc 72 | 73 | General overview: 74 | classify based on the DSCPs and use the policer ids to decide tagging 75 | 76 | 77 | *classify on ingress: 78 | 79 | switch (dscp) { 80 | case AF41: /* tos&0xfc == 0x88 */ 81 | if (!exceed meter1) break; 82 | case AF42: /* tos&0xfc == 0x90 */ 83 | if (!exceed meter2) { 84 | tag as AF42; 85 | break; 86 | } 87 | case AF43: /* tos&0xfc == 0x98 */ 88 | if (!exceed meter3) { 89 | tag as AF43; 90 | break; 91 | } else 92 | drop; 93 | default: 94 | if (!exceed meter4) tag as BE; 95 | else drop; 96 | } 97 | 98 | On the Egress side mark the proper AF tags 99 | -------------------------------------------------------------------------------- /examples/gaiconf: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Setup address label from /etc/gai.conf 5 | # 6 | # Written by YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>, 2010. 7 | # 8 | 9 | IP=ip 10 | DEFAULT_GAICONF=/etc/gai.conf 11 | verbose= 12 | debug= 13 | 14 | function run () 15 | { 16 | if [ x"$verbose" != x"" ]; then 17 | echo "$@" 18 | fi 19 | if [ x"$debug" = x"" ]; then 20 | "$@" 21 | fi 22 | } 23 | 24 | function do_load_config () 25 | { 26 | file=$1; shift 27 | flush=1 28 | cat $file | while read command prefix label; do 29 | if [ x"$command" = x"#label" ]; then 30 | if [ ${flush} = 1 ]; then 31 | run ${IP} -6 addrlabel flush 32 | flush=0 33 | fi 34 | run ${IP} -6 addrlabel add prefix $prefix label $label 35 | fi 36 | done 37 | } 38 | 39 | function do_list_config () 40 | { 41 | ${IP} -6 addrlabel list | while read p pfx l lbl; do 42 | echo label ${pfx} ${lbl} 43 | done 44 | } 45 | 46 | function help () 47 | { 48 | echo "Usage: $0 [-v] {--list | --config [ ${DEFAULT_GAICONF} ] | --default}" 49 | exit 1 50 | } 51 | 52 | TEMP=`getopt -o c::dlv -l config::,default,list,verbose -n gaiconf -- "$@"` 53 | 54 | if [ $? != 0 ]; then 55 | echo "Terminating..." >&2 56 | exit 1 57 | fi 58 | 59 | TEMPFILE=`mktemp` 60 | 61 | eval set -- "$TEMP" 62 | 63 | while true ; do 64 | case "$1" in 65 | -c|--config) 66 | if [ x"$cmd" != x"" ]; then 67 | help 68 | fi 69 | case "$2" in 70 | "") gai_conf="${DEFAULT_GAICONF}" 71 | shift 2 72 | ;; 73 | *) gai_conf="$2" 74 | shift 2 75 | esac 76 | cmd=config 77 | ;; 78 | -d|--default) 79 | if [ x"$cmd" != x"" ]; then 80 | help 81 | fi 82 | gai_conf=${TEMPFILE} 83 | cmd=config 84 | ;; 85 | -l|--list) 86 | if [ x"$cmd" != x"" ]; then 87 | help 88 | fi 89 | cmd=list 90 | shift 91 | ;; 92 | -v) 93 | verbose=1 94 | shift 95 | ;; 96 | --) 97 | shift; 98 | break 99 | ;; 100 | *) 101 | echo "Internal error!" >&2 102 | exit 1 103 | ;; 104 | esac 105 | done 106 | 107 | case "$cmd" in 108 | config) 109 | if [ x"$gai_conf" = x"${TEMPFILE}" ]; then 110 | sed -e 's/^[[:space:]]*//' <<END_OF_DEFAULT >${TEMPFILE} 111 | label ::1/128 0 112 | label ::/0 1 113 | label 2002::/16 2 114 | label ::/96 3 115 | label ::ffff:0:0/96 4 116 | label fec0::/10 5 117 | label fc00::/7 6 118 | label 2001:0::/32 7 119 | END_OF_DEFAULT 120 | fi 121 | do_load_config "$gai_conf" 122 | ;; 123 | list) 124 | do_list_config 125 | ;; 126 | *) 127 | help 128 | ;; 129 | esac 130 | 131 | rm -f "${TEMPFILE}" 132 | 133 | exit 0 134 | 135 | -------------------------------------------------------------------------------- /ip/iplink_macvlan.c: -------------------------------------------------------------------------------- 1 | /* 2 | * iplink_vlan.c VLAN device support 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Patrick McHardy <kaber@trash.net> 10 | * Arnd Bergmann <arnd@arndb.de> 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <string.h> 16 | #include <sys/socket.h> 17 | #include <linux/if_link.h> 18 | 19 | #include "rt_names.h" 20 | #include "utils.h" 21 | #include "ip_common.h" 22 | 23 | static void explain(void) 24 | { 25 | fprintf(stderr, 26 | "Usage: ... macvlan mode { private | vepa | bridge | passthru }\n" 27 | ); 28 | } 29 | 30 | static int mode_arg(void) 31 | { 32 | fprintf(stderr, "Error: argument of \"mode\" must be \"private\", " 33 | "\"vepa\", \"bridge\" or \"passthru\" \n"); 34 | return -1; 35 | } 36 | 37 | static int macvlan_parse_opt(struct link_util *lu, int argc, char **argv, 38 | struct nlmsghdr *n) 39 | { 40 | while (argc > 0) { 41 | if (matches(*argv, "mode") == 0) { 42 | __u32 mode = 0; 43 | NEXT_ARG(); 44 | 45 | if (strcmp(*argv, "private") == 0) 46 | mode = MACVLAN_MODE_PRIVATE; 47 | else if (strcmp(*argv, "vepa") == 0) 48 | mode = MACVLAN_MODE_VEPA; 49 | else if (strcmp(*argv, "bridge") == 0) 50 | mode = MACVLAN_MODE_BRIDGE; 51 | else if (strcmp(*argv, "passthru") == 0) 52 | mode = MACVLAN_MODE_PASSTHRU; 53 | else 54 | return mode_arg(); 55 | 56 | addattr32(n, 1024, IFLA_MACVLAN_MODE, mode); 57 | } else if (matches(*argv, "help") == 0) { 58 | explain(); 59 | return -1; 60 | } else { 61 | fprintf(stderr, "macvlan: unknown option \"%s\"?\n", *argv); 62 | explain(); 63 | return -1; 64 | } 65 | argc--, argv++; 66 | } 67 | 68 | return 0; 69 | } 70 | 71 | static void macvlan_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[]) 72 | { 73 | __u32 mode; 74 | 75 | if (!tb) 76 | return; 77 | 78 | if (!tb[IFLA_MACVLAN_MODE] || 79 | RTA_PAYLOAD(tb[IFLA_MACVLAN_MODE]) < sizeof(__u32)) 80 | return; 81 | 82 | mode = rta_getattr_u32(tb[IFLA_VLAN_ID]); 83 | fprintf(f, " mode %s ", 84 | mode == MACVLAN_MODE_PRIVATE ? "private" 85 | : mode == MACVLAN_MODE_VEPA ? "vepa" 86 | : mode == MACVLAN_MODE_BRIDGE ? "bridge" 87 | : mode == MACVLAN_MODE_PASSTHRU ? "passthru" 88 | : "unknown"); 89 | } 90 | 91 | struct link_util macvlan_link_util = { 92 | .id = "macvlan", 93 | .maxattr = IFLA_MACVLAN_MAX, 94 | .parse_opt = macvlan_parse_opt, 95 | .print_opt = macvlan_print_opt, 96 | }; 97 | -------------------------------------------------------------------------------- /tc/q_fifo.c: -------------------------------------------------------------------------------- 1 | /* 2 | * q_fifo.c FIFO. 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 | * 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <unistd.h> 16 | #include <syslog.h> 17 | #include <fcntl.h> 18 | #include <sys/socket.h> 19 | #include <netinet/in.h> 20 | #include <arpa/inet.h> 21 | #include <string.h> 22 | 23 | #include "utils.h" 24 | #include "tc_util.h" 25 | 26 | static void explain(void) 27 | { 28 | fprintf(stderr, "Usage: ... <[p|b]fifo | pfifo_head_drop> [ limit NUMBER ]\n"); 29 | } 30 | 31 | static int fifo_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) 32 | { 33 | int ok=0; 34 | struct tc_fifo_qopt opt; 35 | memset(&opt, 0, sizeof(opt)); 36 | 37 | while (argc > 0) { 38 | if (strcmp(*argv, "limit") == 0) { 39 | NEXT_ARG(); 40 | if (get_size(&opt.limit, *argv)) { 41 | fprintf(stderr, "%s: Illegal value for \"limit\": \"%s\"\n", qu->id, *argv); 42 | return -1; 43 | } 44 | ok++; 45 | } else if (strcmp(*argv, "help") == 0) { 46 | explain(); 47 | return -1; 48 | } else { 49 | fprintf(stderr, "%s: unknown parameter \"%s\"\n", qu->id, *argv); 50 | explain(); 51 | return -1; 52 | } 53 | argc--; argv++; 54 | } 55 | 56 | if (ok) 57 | addattr_l(n, 1024, TCA_OPTIONS, &opt, sizeof(opt)); 58 | return 0; 59 | } 60 | 61 | static int fifo_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) 62 | { 63 | struct tc_fifo_qopt *qopt; 64 | 65 | if (opt == NULL) 66 | return 0; 67 | 68 | if (RTA_PAYLOAD(opt) < sizeof(*qopt)) 69 | return -1; 70 | qopt = RTA_DATA(opt); 71 | if (strcmp(qu->id, "bfifo") == 0) { 72 | SPRINT_BUF(b1); 73 | fprintf(f, "limit %s", sprint_size(qopt->limit, b1)); 74 | } else 75 | fprintf(f, "limit %up", qopt->limit); 76 | return 0; 77 | } 78 | 79 | 80 | struct qdisc_util bfifo_qdisc_util = { 81 | .id = "bfifo", 82 | .parse_qopt = fifo_parse_opt, 83 | .print_qopt = fifo_print_opt, 84 | }; 85 | 86 | struct qdisc_util pfifo_qdisc_util = { 87 | .id = "pfifo", 88 | .parse_qopt = fifo_parse_opt, 89 | .print_qopt = fifo_print_opt, 90 | }; 91 | 92 | struct qdisc_util pfifo_head_drop_qdisc_util = { 93 | .id = "pfifo_head_drop", 94 | .parse_qopt = fifo_parse_opt, 95 | .print_qopt = fifo_print_opt, 96 | }; 97 | 98 | extern int prio_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt); 99 | struct qdisc_util pfifo_fast_qdisc_util = { 100 | .id = "pfifo_fast", 101 | .print_qopt = prio_print_opt, 102 | }; 103 | -------------------------------------------------------------------------------- /examples/cbqinit.eth1: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | 3 | TC=/home/root/tc 4 | IP=/home/root/ip 5 | DEVICE=eth1 6 | BANDWIDTH="bandwidth 10Mbit" 7 | 8 | # Attach CBQ on $DEVICE. It will have handle 1:. 9 | # $BANDWIDTH is real $DEVICE bandwidth (10Mbit). 10 | # avpkt is average packet size. 11 | # mpu is minimal packet size. 12 | 13 | $TC qdisc add dev $DEVICE root handle 1: cbq \ 14 | $BANDWIDTH avpkt 1000 mpu 64 15 | 16 | # Create root class with classid 1:1. This step is not necessary. 17 | # bandwidth is the same as on CBQ itself. 18 | # rate == all the bandwidth 19 | # allot is MTU + MAC header 20 | # maxburst measure allowed class burstiness (please,read S.Floyd and VJ papers) 21 | # est 1sec 8sec means, that kernel will evaluate average rate 22 | # on this class with period 1sec and time constant 8sec. 23 | # This rate is viewed with "tc -s class ls dev $DEVICE" 24 | 25 | $TC class add dev $DEVICE parent 1:0 classid :1 est 1sec 8sec cbq \ 26 | $BANDWIDTH rate 10Mbit allot 1514 maxburst 50 avpkt 1000 27 | 28 | # Bulk. 29 | # New parameters are: 30 | # weight, which is set to be proportional to 31 | # "rate". It is not necessary, weight=1 will work as well. 32 | # defmap and split say that best effort ttraffic, not classfied 33 | # by another means will fall to this class. 34 | 35 | $TC class add dev $DEVICE parent 1:1 classid :2 est 1sec 8sec cbq \ 36 | $BANDWIDTH rate 4Mbit allot 1514 weight 500Kbit \ 37 | prio 6 maxburst 50 avpkt 1000 split 1:0 defmap ff3d 38 | 39 | # OPTIONAL. 40 | # Attach "sfq" qdisc to this class, quantum is MTU, perturb 41 | # gives period of hash function perturbation in seconds. 42 | # 43 | $TC qdisc add dev $DEVICE parent 1:2 sfq quantum 1514b perturb 15 44 | 45 | # Interactive-burst class 46 | 47 | $TC class add dev $DEVICE parent 1:1 classid :3 est 2sec 16sec cbq \ 48 | $BANDWIDTH rate 1Mbit allot 1514 weight 100Kbit \ 49 | prio 2 maxburst 100 avpkt 1000 split 1:0 defmap c0 50 | 51 | $TC qdisc add dev $DEVICE parent 1:3 sfq quantum 1514b perturb 15 52 | 53 | # Background. 54 | 55 | $TC class add dev $DEVICE parent 1:1 classid :4 est 1sec 8sec cbq \ 56 | $BANDWIDTH rate 100Kbit allot 1514 weight 10Mbit \ 57 | prio 7 maxburst 10 avpkt 1000 split 1:0 defmap 2 58 | 59 | $TC qdisc add dev $DEVICE parent 1:4 sfq quantum 1514b perturb 15 60 | 61 | # Realtime class for RSVP 62 | 63 | $TC class add dev $DEVICE parent 1:1 classid 1:7FFE cbq \ 64 | rate 5Mbit $BANDWIDTH allot 1514b avpkt 1000 \ 65 | maxburst 20 66 | 67 | # Reclassified realtime traffic 68 | # 69 | # New element: split is not 1:0, but 1:7FFE. It means, 70 | # that only real-time packets, which violated policing filters 71 | # or exceeded reshaping buffers will fall to it. 72 | 73 | $TC class add dev $DEVICE parent 1:7FFE classid 1:7FFF est 4sec 32sec cbq \ 74 | rate 1Mbit $BANDWIDTH allot 1514b avpkt 1000 weight 10Kbit \ 75 | prio 6 maxburst 10 split 1:7FFE defmap ffff 76 | 77 | -------------------------------------------------------------------------------- /include/linux/hdlc/ioctl.h: -------------------------------------------------------------------------------- 1 | #ifndef __HDLC_IOCTL_H__ 2 | #define __HDLC_IOCTL_H__ 3 | 4 | 5 | #define GENERIC_HDLC_VERSION 4 /* For synchronization with sethdlc utility */ 6 | 7 | #define CLOCK_DEFAULT 0 /* Default setting */ 8 | #define CLOCK_EXT 1 /* External TX and RX clock - DTE */ 9 | #define CLOCK_INT 2 /* Internal TX and RX clock - DCE */ 10 | #define CLOCK_TXINT 3 /* Internal TX and external RX clock */ 11 | #define CLOCK_TXFROMRX 4 /* TX clock derived from external RX clock */ 12 | 13 | 14 | #define ENCODING_DEFAULT 0 /* Default setting */ 15 | #define ENCODING_NRZ 1 16 | #define ENCODING_NRZI 2 17 | #define ENCODING_FM_MARK 3 18 | #define ENCODING_FM_SPACE 4 19 | #define ENCODING_MANCHESTER 5 20 | 21 | 22 | #define PARITY_DEFAULT 0 /* Default setting */ 23 | #define PARITY_NONE 1 /* No parity */ 24 | #define PARITY_CRC16_PR0 2 /* CRC16, initial value 0x0000 */ 25 | #define PARITY_CRC16_PR1 3 /* CRC16, initial value 0xFFFF */ 26 | #define PARITY_CRC16_PR0_CCITT 4 /* CRC16, initial 0x0000, ITU-T version */ 27 | #define PARITY_CRC16_PR1_CCITT 5 /* CRC16, initial 0xFFFF, ITU-T version */ 28 | #define PARITY_CRC32_PR0_CCITT 6 /* CRC32, initial value 0x00000000 */ 29 | #define PARITY_CRC32_PR1_CCITT 7 /* CRC32, initial value 0xFFFFFFFF */ 30 | 31 | #define LMI_DEFAULT 0 /* Default setting */ 32 | #define LMI_NONE 1 /* No LMI, all PVCs are static */ 33 | #define LMI_ANSI 2 /* ANSI Annex D */ 34 | #define LMI_CCITT 3 /* ITU-T Annex A */ 35 | #define LMI_CISCO 4 /* The "original" LMI, aka Gang of Four */ 36 | 37 | #ifndef __ASSEMBLY__ 38 | 39 | typedef struct { 40 | unsigned int clock_rate; /* bits per second */ 41 | unsigned int clock_type; /* internal, external, TX-internal etc. */ 42 | unsigned short loopback; 43 | } sync_serial_settings; /* V.35, V.24, X.21 */ 44 | 45 | typedef struct { 46 | unsigned int clock_rate; /* bits per second */ 47 | unsigned int clock_type; /* internal, external, TX-internal etc. */ 48 | unsigned short loopback; 49 | unsigned int slot_map; 50 | } te1_settings; /* T1, E1 */ 51 | 52 | typedef struct { 53 | unsigned short encoding; 54 | unsigned short parity; 55 | } raw_hdlc_proto; 56 | 57 | typedef struct { 58 | unsigned int t391; 59 | unsigned int t392; 60 | unsigned int n391; 61 | unsigned int n392; 62 | unsigned int n393; 63 | unsigned short lmi; 64 | unsigned short dce; /* 1 for DCE (network side) operation */ 65 | } fr_proto; 66 | 67 | typedef struct { 68 | unsigned int dlci; 69 | } fr_proto_pvc; /* for creating/deleting FR PVCs */ 70 | 71 | typedef struct { 72 | unsigned int dlci; 73 | char master[IFNAMSIZ]; /* Name of master FRAD device */ 74 | }fr_proto_pvc_info; /* for returning PVC information only */ 75 | 76 | typedef struct { 77 | unsigned int interval; 78 | unsigned int timeout; 79 | } cisco_proto; 80 | 81 | /* PPP doesn't need any info now - supply length = 0 to ioctl */ 82 | 83 | #endif /* __ASSEMBLY__ */ 84 | #endif /* __HDLC_IOCTL_H__ */ 85 | -------------------------------------------------------------------------------- /lib/ll_proto.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ll_proto.c 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 | */ 11 | 12 | #include <stdio.h> 13 | #include <stdlib.h> 14 | #include <unistd.h> 15 | #include <syslog.h> 16 | #include <fcntl.h> 17 | #include <sys/ioctl.h> 18 | #include <sys/socket.h> 19 | #include <sys/ioctl.h> 20 | #include <netinet/in.h> 21 | #include <arpa/inet.h> 22 | #include <string.h> 23 | 24 | #include <linux/netdevice.h> 25 | #include <linux/if_arp.h> 26 | #include <linux/sockios.h> 27 | 28 | #include "utils.h" 29 | #include "rt_names.h" 30 | 31 | 32 | #define __PF(f,n) { ETH_P_##f, #n }, 33 | static const struct { 34 | int id; 35 | const char *name; 36 | } llproto_names[] = { 37 | __PF(LOOP,loop) 38 | __PF(PUP,pup) 39 | __PF(PUPAT,pupat) 40 | __PF(IP,ip) 41 | __PF(X25,x25) 42 | __PF(ARP,arp) 43 | __PF(BPQ,bpq) 44 | __PF(IEEEPUP,ieeepup) 45 | __PF(IEEEPUPAT,ieeepupat) 46 | __PF(DEC,dec) 47 | __PF(DNA_DL,dna_dl) 48 | __PF(DNA_RC,dna_rc) 49 | __PF(DNA_RT,dna_rt) 50 | __PF(LAT,lat) 51 | __PF(DIAG,diag) 52 | __PF(CUST,cust) 53 | __PF(SCA,sca) 54 | __PF(RARP,rarp) 55 | __PF(ATALK,atalk) 56 | __PF(AARP,aarp) 57 | __PF(IPX,ipx) 58 | __PF(IPV6,ipv6) 59 | __PF(PPP_DISC,ppp_disc) 60 | __PF(PPP_SES,ppp_ses) 61 | __PF(ATMMPOA,atmmpoa) 62 | __PF(ATMFATE,atmfate) 63 | __PF(802_3,802_3) 64 | __PF(AX25,ax25) 65 | __PF(ALL,all) 66 | __PF(802_2,802_2) 67 | __PF(SNAP,snap) 68 | __PF(DDCMP,ddcmp) 69 | __PF(WAN_PPP,wan_ppp) 70 | __PF(PPP_MP,ppp_mp) 71 | __PF(LOCALTALK,localtalk) 72 | __PF(CAN,can) 73 | __PF(PPPTALK,ppptalk) 74 | __PF(TR_802_2,tr_802_2) 75 | __PF(MOBITEX,mobitex) 76 | __PF(CONTROL,control) 77 | __PF(IRDA,irda) 78 | __PF(ECONET,econet) 79 | __PF(TIPC,tipc) 80 | __PF(AOE,aoe) 81 | 82 | { 0x8100, "802.1Q" }, 83 | { 0x88cc, "LLDP" }, 84 | { ETH_P_IP, "ipv4" }, 85 | }; 86 | #undef __PF 87 | 88 | 89 | const char * ll_proto_n2a(unsigned short id, char *buf, int len) 90 | { 91 | int i; 92 | 93 | id = ntohs(id); 94 | 95 | for (i=0; i<sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { 96 | if (llproto_names[i].id == id) 97 | return llproto_names[i].name; 98 | } 99 | snprintf(buf, len, "[%d]", id); 100 | return buf; 101 | } 102 | 103 | int ll_proto_a2n(unsigned short *id, const char *buf) 104 | { 105 | int i; 106 | for (i=0; i < sizeof(llproto_names)/sizeof(llproto_names[0]); i++) { 107 | if (strcasecmp(llproto_names[i].name, buf) == 0) { 108 | *id = htons(llproto_names[i].id); 109 | return 0; 110 | } 111 | } 112 | if (get_u16(id, buf, 0)) 113 | return -1; 114 | *id = htons(*id); 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /tc/tc_monitor.c: -------------------------------------------------------------------------------- 1 | /* 2 | * tc_monitor.c "tc monitor". 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Jamal Hadi Salim 10 | * 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <unistd.h> 16 | #include <syslog.h> 17 | #include <fcntl.h> 18 | #include <sys/socket.h> 19 | #include <netinet/in.h> 20 | #include <arpa/inet.h> 21 | #include <string.h> 22 | #include <time.h> 23 | #include "rt_names.h" 24 | #include "utils.h" 25 | #include "tc_util.h" 26 | #include "tc_common.h" 27 | 28 | 29 | static void usage(void) __attribute__((noreturn)); 30 | 31 | static void usage(void) 32 | { 33 | fprintf(stderr, "Usage: tc monitor\n"); 34 | exit(-1); 35 | } 36 | 37 | 38 | static int accept_tcmsg(const struct sockaddr_nl *who, 39 | struct nlmsghdr *n, void *arg) 40 | { 41 | FILE *fp = (FILE*)arg; 42 | 43 | if (n->nlmsg_type == RTM_NEWTFILTER || n->nlmsg_type == RTM_DELTFILTER) { 44 | print_filter(who, n, arg); 45 | return 0; 46 | } 47 | if (n->nlmsg_type == RTM_NEWTCLASS || n->nlmsg_type == RTM_DELTCLASS) { 48 | print_class(who, n, arg); 49 | return 0; 50 | } 51 | if (n->nlmsg_type == RTM_NEWQDISC || n->nlmsg_type == RTM_DELQDISC) { 52 | print_qdisc(who, n, arg); 53 | return 0; 54 | } 55 | if (n->nlmsg_type == RTM_GETACTION || n->nlmsg_type == RTM_NEWACTION || 56 | n->nlmsg_type == RTM_DELACTION) { 57 | print_action(who, n, arg); 58 | return 0; 59 | } 60 | if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && 61 | n->nlmsg_type != NLMSG_DONE) { 62 | fprintf(fp, "Unknown message: length %08d type %08x flags %08x\n", 63 | n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); 64 | } 65 | return 0; 66 | } 67 | 68 | int do_tcmonitor(int argc, char **argv) 69 | { 70 | struct rtnl_handle rth; 71 | char *file = NULL; 72 | unsigned groups = nl_mgrp(RTNLGRP_TC); 73 | 74 | while (argc > 0) { 75 | if (matches(*argv, "file") == 0) { 76 | NEXT_ARG(); 77 | file = *argv; 78 | } else { 79 | if (matches(*argv, "help") == 0) { 80 | usage(); 81 | } else { 82 | fprintf(stderr, "Argument \"%s\" is unknown, try \"tc monitor help\".\n", *argv); 83 | exit(-1); 84 | } 85 | } 86 | argc--; argv++; 87 | } 88 | 89 | if (file) { 90 | FILE *fp; 91 | fp = fopen(file, "r"); 92 | if (fp == NULL) { 93 | perror("Cannot fopen"); 94 | exit(-1); 95 | } 96 | return rtnl_from_file(fp, accept_tcmsg, (void*)stdout); 97 | } 98 | 99 | if (rtnl_open(&rth, groups) < 0) 100 | exit(1); 101 | 102 | ll_init_map(&rth); 103 | 104 | if (rtnl_listen(&rth, accept_tcmsg, (void*)stdout) < 0) { 105 | rtnl_close(&rth); 106 | exit(2); 107 | } 108 | 109 | rtnl_close(&rth); 110 | exit(0); 111 | } 112 | -------------------------------------------------------------------------------- /ip/rtm_map.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rtm_map.c 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 | * 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <unistd.h> 16 | #include <syslog.h> 17 | #include <fcntl.h> 18 | #include <string.h> 19 | #include <sys/socket.h> 20 | #include <netinet/in.h> 21 | 22 | #include "rt_names.h" 23 | #include "utils.h" 24 | 25 | char *rtnl_rtntype_n2a(int id, char *buf, int len) 26 | { 27 | switch (id) { 28 | case RTN_UNSPEC: 29 | return "none"; 30 | case RTN_UNICAST: 31 | return "unicast"; 32 | case RTN_LOCAL: 33 | return "local"; 34 | case RTN_BROADCAST: 35 | return "broadcast"; 36 | case RTN_ANYCAST: 37 | return "anycast"; 38 | case RTN_MULTICAST: 39 | return "multicast"; 40 | case RTN_BLACKHOLE: 41 | return "blackhole"; 42 | case RTN_UNREACHABLE: 43 | return "unreachable"; 44 | case RTN_PROHIBIT: 45 | return "prohibit"; 46 | case RTN_THROW: 47 | return "throw"; 48 | case RTN_NAT: 49 | return "nat"; 50 | case RTN_XRESOLVE: 51 | return "xresolve"; 52 | default: 53 | snprintf(buf, len, "%d", id); 54 | return buf; 55 | } 56 | } 57 | 58 | 59 | int rtnl_rtntype_a2n(int *id, char *arg) 60 | { 61 | char *end; 62 | unsigned long res; 63 | 64 | if (strcmp(arg, "local") == 0) 65 | res = RTN_LOCAL; 66 | else if (strcmp(arg, "nat") == 0) 67 | res = RTN_NAT; 68 | else if (matches(arg, "broadcast") == 0 || 69 | strcmp(arg, "brd") == 0) 70 | res = RTN_BROADCAST; 71 | else if (matches(arg, "anycast") == 0) 72 | res = RTN_ANYCAST; 73 | else if (matches(arg, "multicast") == 0) 74 | res = RTN_MULTICAST; 75 | else if (matches(arg, "prohibit") == 0) 76 | res = RTN_PROHIBIT; 77 | else if (matches(arg, "unreachable") == 0) 78 | res = RTN_UNREACHABLE; 79 | else if (matches(arg, "blackhole") == 0) 80 | res = RTN_BLACKHOLE; 81 | else if (matches(arg, "xresolve") == 0) 82 | res = RTN_XRESOLVE; 83 | else if (matches(arg, "unicast") == 0) 84 | res = RTN_UNICAST; 85 | else if (strcmp(arg, "throw") == 0) 86 | res = RTN_THROW; 87 | else { 88 | res = strtoul(arg, &end, 0); 89 | if (!end || end == arg || *end || res > 255) 90 | return -1; 91 | } 92 | *id = res; 93 | return 0; 94 | } 95 | 96 | int get_rt_realms(__u32 *realms, char *arg) 97 | { 98 | __u32 realm = 0; 99 | char *p = strchr(arg, '/'); 100 | 101 | *realms = 0; 102 | if (p) { 103 | *p = 0; 104 | if (rtnl_rtrealm_a2n(realms, arg)) { 105 | *p = '/'; 106 | return -1; 107 | } 108 | *realms <<= 16; 109 | *p = '/'; 110 | arg = p+1; 111 | } 112 | if (*arg && rtnl_rtrealm_a2n(&realm, arg)) 113 | return -1; 114 | *realms |= realm; 115 | return 0; 116 | } 117 | -------------------------------------------------------------------------------- /include/linux/if_tunnel.h: -------------------------------------------------------------------------------- 1 | #ifndef _IF_TUNNEL_H_ 2 | #define _IF_TUNNEL_H_ 3 | 4 | #include <linux/types.h> 5 | #include <asm/byteorder.h> 6 | 7 | 8 | #define SIOCGETTUNNEL (SIOCDEVPRIVATE + 0) 9 | #define SIOCADDTUNNEL (SIOCDEVPRIVATE + 1) 10 | #define SIOCDELTUNNEL (SIOCDEVPRIVATE + 2) 11 | #define SIOCCHGTUNNEL (SIOCDEVPRIVATE + 3) 12 | #define SIOCGETPRL (SIOCDEVPRIVATE + 4) 13 | #define SIOCADDPRL (SIOCDEVPRIVATE + 5) 14 | #define SIOCDELPRL (SIOCDEVPRIVATE + 6) 15 | #define SIOCCHGPRL (SIOCDEVPRIVATE + 7) 16 | #define SIOCGET6RD (SIOCDEVPRIVATE + 8) 17 | #define SIOCADD6RD (SIOCDEVPRIVATE + 9) 18 | #define SIOCDEL6RD (SIOCDEVPRIVATE + 10) 19 | #define SIOCCHG6RD (SIOCDEVPRIVATE + 11) 20 | 21 | #define GRE_CSUM __cpu_to_be16(0x8000) 22 | #define GRE_ROUTING __cpu_to_be16(0x4000) 23 | #define GRE_KEY __cpu_to_be16(0x2000) 24 | #define GRE_SEQ __cpu_to_be16(0x1000) 25 | #define GRE_STRICT __cpu_to_be16(0x0800) 26 | #define GRE_REC __cpu_to_be16(0x0700) 27 | #define GRE_FLAGS __cpu_to_be16(0x00F8) 28 | #define GRE_VERSION __cpu_to_be16(0x0007) 29 | 30 | struct ip_tunnel_parm { 31 | char name[IFNAMSIZ]; 32 | int link; 33 | __be16 i_flags; 34 | __be16 o_flags; 35 | __be32 i_key; 36 | __be32 o_key; 37 | struct iphdr iph; 38 | }; 39 | 40 | enum { 41 | IFLA_IPTUN_UNSPEC, 42 | IFLA_IPTUN_LINK, 43 | IFLA_IPTUN_LOCAL, 44 | IFLA_IPTUN_REMOTE, 45 | IFLA_IPTUN_TTL, 46 | IFLA_IPTUN_TOS, 47 | IFLA_IPTUN_ENCAP_LIMIT, 48 | IFLA_IPTUN_FLOWINFO, 49 | IFLA_IPTUN_FLAGS, 50 | IFLA_IPTUN_PROTO, 51 | IFLA_IPTUN_PMTUDISC, 52 | IFLA_IPTUN_6RD_PREFIX, 53 | IFLA_IPTUN_6RD_RELAY_PREFIX, 54 | IFLA_IPTUN_6RD_PREFIXLEN, 55 | IFLA_IPTUN_6RD_RELAY_PREFIXLEN, 56 | __IFLA_IPTUN_MAX, 57 | }; 58 | #define IFLA_IPTUN_MAX (__IFLA_IPTUN_MAX - 1) 59 | 60 | /* SIT-mode i_flags */ 61 | #define SIT_ISATAP 0x0001 62 | 63 | struct ip_tunnel_prl { 64 | __be32 addr; 65 | __u16 flags; 66 | __u16 __reserved; 67 | __u32 datalen; 68 | __u32 __reserved2; 69 | /* data follows */ 70 | }; 71 | 72 | /* PRL flags */ 73 | #define PRL_DEFAULT 0x0001 74 | 75 | struct ip_tunnel_6rd { 76 | struct in6_addr prefix; 77 | __be32 relay_prefix; 78 | __u16 prefixlen; 79 | __u16 relay_prefixlen; 80 | }; 81 | 82 | enum { 83 | IFLA_GRE_UNSPEC, 84 | IFLA_GRE_LINK, 85 | IFLA_GRE_IFLAGS, 86 | IFLA_GRE_OFLAGS, 87 | IFLA_GRE_IKEY, 88 | IFLA_GRE_OKEY, 89 | IFLA_GRE_LOCAL, 90 | IFLA_GRE_REMOTE, 91 | IFLA_GRE_TTL, 92 | IFLA_GRE_TOS, 93 | IFLA_GRE_PMTUDISC, 94 | IFLA_GRE_ENCAP_LIMIT, 95 | IFLA_GRE_FLOWINFO, 96 | IFLA_GRE_FLAGS, 97 | __IFLA_GRE_MAX, 98 | }; 99 | 100 | #define IFLA_GRE_MAX (__IFLA_GRE_MAX - 1) 101 | 102 | /* VTI-mode i_flags */ 103 | #define VTI_ISVTI 0x0001 104 | 105 | enum { 106 | IFLA_VTI_UNSPEC, 107 | IFLA_VTI_LINK, 108 | IFLA_VTI_IKEY, 109 | IFLA_VTI_OKEY, 110 | IFLA_VTI_LOCAL, 111 | IFLA_VTI_REMOTE, 112 | __IFLA_VTI_MAX, 113 | }; 114 | 115 | #define IFLA_VTI_MAX (__IFLA_VTI_MAX - 1) 116 | #endif /* _IF_TUNNEL_H_ */ 117 | -------------------------------------------------------------------------------- /man/man8/tc-drr.8: -------------------------------------------------------------------------------- 1 | .TH TC 8 "January 2010" "iproute2" "Linux" 2 | .SH NAME 3 | drr \- deficit round robin scheduler 4 | .SH SYNOPSIS 5 | .B tc qdisc ... add drr 6 | .B [ quantum 7 | bytes 8 | .B ] 9 | 10 | .SH DESCRIPTION 11 | 12 | The Deficit Round Robin Scheduler is a classful queuing discipline as 13 | a more flexible replacement for Stochastic Fairness Queuing. 14 | 15 | Unlike SFQ, there are no built-in queues \-\- you need to add classes 16 | and then set up filters to classify packets accordingly. 17 | This can be useful e.g. for using RED qdiscs with different settings for particular 18 | traffic. There is no default class \-\- if a packet cannot be classified, 19 | it is dropped. 20 | 21 | .SH ALGORITHM 22 | Each class is assigned a deficit counter, initialized to 23 | .B quantum. 24 | 25 | DRR maintains an (internal) ''active'' list of classes whose qdiscs are 26 | non-empty. This list is used for dequeuing. A packet is dequeued from 27 | the class at the head of the list if the packet size is smaller or equal 28 | to the deficit counter. If the counter is too small, it is increased by 29 | .B quantum 30 | and the scheduler moves on to the next class in the active list. 31 | 32 | 33 | .SH PARAMETERS 34 | .TP 35 | quantum 36 | Amount of bytes a flow is allowed to dequeue before the scheduler moves to 37 | the next class. Defaults to the MTU of the interface. The minimum value is 1. 38 | 39 | .SH EXAMPLE & USAGE 40 | 41 | To attach to device eth0, using the interface MTU as its quantum: 42 | .P 43 | # tc qdisc add dev eth0 handle 1 root drr 44 | .P 45 | Adding two classes: 46 | .P 47 | # tc class add dev eth0 parent 1: classid 1:1 drr 48 | .br 49 | # tc class add dev eth0 parent 1: classid 1:2 drr 50 | .P 51 | You also need to add at least one filter to classify packets. 52 | .P 53 | # tc filter add dev eth0 protocol .. classid 1:1 54 | .P 55 | 56 | Like SFQ, DRR is only useful when it owns the queue \-\- it is a pure scheduler and does 57 | not delay packets. Attaching non-work-conserving qdiscs like tbf to it does not make 58 | sense \-\- other qdiscs in the active list will also become inactive until the dequeue 59 | operation succeeds. Embed DRR within another qdisc like HTB or HFSC to ensure it owns the queue. 60 | .P 61 | You can mimic SFQ behavior by assigning packets to the attached classes using the 62 | flow filter: 63 | 64 | .B tc qdisc add dev .. drr 65 | 66 | .B for i in .. 1024;do 67 | .br 68 | .B "\ttc class add dev .. classid $handle:$(print %x $i)" 69 | .br 70 | .B "\ttc qdisc add dev .. fifo limit 16" 71 | .br 72 | .B done 73 | 74 | .B tc filter add .. protocol ip .. $handle flow hash keys src,dst,proto,proto-src,proto-dst divisor 1024 perturb 10 75 | 76 | 77 | .SH SOURCE 78 | .TP 79 | o 80 | M. Shreedhar and George Varghese "Efficient Fair 81 | Queuing using Deficit Round Robin", Proc. SIGCOMM 95. 82 | 83 | .SH NOTES 84 | 85 | This implementation does not drop packets from the longest queue on overrun, 86 | as limits are handled by the individual child qdiscs. 87 | 88 | .SH SEE ALSO 89 | .BR tc (8), 90 | .BR tc-htb (8), 91 | .BR tc-sfq (8) 92 | 93 | .SH AUTHOR 94 | sched_drr was written by Patrick McHardy. 95 | 96 | -------------------------------------------------------------------------------- /doc/actions/gact-usage: -------------------------------------------------------------------------------- 1 | 2 | gact <ACTION> [RAND] [INDEX] 3 | 4 | Where: 5 | ACTION := reclassify | drop | continue | pass | ok 6 | RAND := random <RANDTYPE> <ACTION> <VAL> 7 | RANDTYPE := netrand | determ 8 | VAL : = value not exceeding 10000 9 | INDEX := index value used 10 | 11 | ACTION semantics 12 | - pass and ok are equivalent to accept 13 | - continue allows to restart classification lookup 14 | - drop drops packets 15 | - reclassify implies continue classification where we left off 16 | 17 | randomization 18 | -------------- 19 | 20 | At the moment there are only two algorithms. One is deterministic 21 | and the other uses internal kernel netrand. 22 | 23 | Examples: 24 | 25 | Rules can be installed on both ingress and egress - this shows ingress 26 | only 27 | 28 | tc qdisc add dev eth0 ingress 29 | 30 | # example 1 31 | tc filter add dev eth0 parent ffff: protocol ip prio 6 u32 match ip src \ 32 | 10.0.0.9/32 flowid 1:16 action drop 33 | 34 | ping -c 20 10.0.0.9 35 | 36 | -- 37 | filter u32 38 | filter u32 fh 800: ht divisor 1 39 | filter u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:16 (rule hit 32 success 20) 40 | match 0a000009/ffffffff at 12 (success 20 ) 41 | action order 1: gact action drop 42 | random type none pass val 0 43 | index 1 ref 1 bind 1 installed 59 sec used 35 sec 44 | Sent 1680 bytes 20 pkts (dropped 20, overlimits 0 ) 45 | 46 | ---- 47 | 48 | # example 2 49 | #allow 1 out 10 randomly using the netrand generator 50 | tc filter add dev eth0 parent ffff: protocol ip prio 6 u32 match ip src \ 51 | 10.0.0.9/32 flowid 1:16 action drop random netrand ok 10 52 | 53 | ping -c 20 10.0.0.9 54 | 55 | ---- 56 | filter protocol ip pref 6 u32 filter protocol ip pref 6 u32 fh 800: ht divisor 1filter protocol ip pref 6 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:16 (rule hit 20 success 20) 57 | match 0a000009/ffffffff at 12 (success 20 ) 58 | action order 1: gact action drop 59 | random type netrand pass val 10 60 | index 5 ref 1 bind 1 installed 49 sec used 25 sec 61 | Sent 1680 bytes 20 pkts (dropped 16, overlimits 0 ) 62 | 63 | -------- 64 | #alternative: deterministically accept every second packet 65 | tc filter add dev eth0 parent ffff: protocol ip prio 6 u32 match ip src \ 66 | 10.0.0.9/32 flowid 1:16 action drop random determ ok 2 67 | 68 | ping -c 20 10.0.0.9 69 | 70 | tc -s filter show parent ffff: dev eth0 71 | ----- 72 | filter protocol ip pref 6 u32 filter protocol ip pref 6 u32 fh 800: ht divisor 1filter protocol ip pref 6 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:16 (rule hit 20 success 20) 73 | match 0a000009/ffffffff at 12 (success 20 ) 74 | action order 1: gact action drop 75 | random type determ pass val 2 76 | index 4 ref 1 bind 1 installed 118 sec used 82 sec 77 | Sent 1680 bytes 20 pkts (dropped 10, overlimits 0 ) 78 | ----- 79 | 80 | -------------------------------------------------------------------------------- /lib/ll_types.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ll_types.c 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> 10 | */ 11 | 12 | #include <stdio.h> 13 | #include <stdlib.h> 14 | #include <unistd.h> 15 | #include <syslog.h> 16 | #include <fcntl.h> 17 | #include <sys/ioctl.h> 18 | #include <sys/socket.h> 19 | #include <sys/ioctl.h> 20 | #include <netinet/in.h> 21 | #include <arpa/inet.h> 22 | #include <string.h> 23 | 24 | #include <linux/netdevice.h> 25 | #include <linux/if_arp.h> 26 | #include <linux/sockios.h> 27 | 28 | #include "rt_names.h" 29 | 30 | const char * ll_type_n2a(int type, char *buf, int len) 31 | { 32 | #define __PF(f,n) { ARPHRD_##f, #n }, 33 | static const struct { 34 | int type; 35 | const char *name; 36 | } arphrd_names[] = { 37 | { 0, "generic" }, 38 | __PF(ETHER,ether) 39 | __PF(EETHER,eether) 40 | __PF(AX25,ax25) 41 | __PF(PRONET,pronet) 42 | __PF(CHAOS,chaos) 43 | __PF(IEEE802,ieee802) 44 | __PF(ARCNET,arcnet) 45 | __PF(APPLETLK,atalk) 46 | __PF(DLCI,dlci) 47 | __PF(ATM,atm) 48 | __PF(METRICOM,metricom) 49 | __PF(IEEE1394,ieee1394) 50 | __PF(INFINIBAND,infiniband) 51 | __PF(SLIP,slip) 52 | __PF(CSLIP,cslip) 53 | __PF(SLIP6,slip6) 54 | __PF(CSLIP6,cslip6) 55 | __PF(RSRVD,rsrvd) 56 | __PF(ADAPT,adapt) 57 | __PF(ROSE,rose) 58 | __PF(X25,x25) 59 | __PF(HWX25,hwx25) 60 | __PF(CAN,can) 61 | __PF(PPP,ppp) 62 | __PF(HDLC,hdlc) 63 | __PF(LAPB,lapb) 64 | __PF(DDCMP,ddcmp) 65 | __PF(RAWHDLC,rawhdlc) 66 | __PF(TUNNEL,ipip) 67 | __PF(TUNNEL6,tunnel6) 68 | __PF(FRAD,frad) 69 | __PF(SKIP,skip) 70 | __PF(LOOPBACK,loopback) 71 | __PF(LOCALTLK,ltalk) 72 | __PF(FDDI,fddi) 73 | __PF(BIF,bif) 74 | __PF(SIT,sit) 75 | __PF(IPDDP,ip/ddp) 76 | __PF(IPGRE,gre) 77 | __PF(PIMREG,pimreg) 78 | __PF(HIPPI,hippi) 79 | __PF(ASH,ash) 80 | __PF(ECONET,econet) 81 | __PF(IRDA,irda) 82 | __PF(FCPP,fcpp) 83 | __PF(FCAL,fcal) 84 | __PF(FCPL,fcpl) 85 | __PF(FCFABRIC,fcfb0) 86 | __PF(FCFABRIC+1,fcfb1) 87 | __PF(FCFABRIC+2,fcfb2) 88 | __PF(FCFABRIC+3,fcfb3) 89 | __PF(FCFABRIC+4,fcfb4) 90 | __PF(FCFABRIC+5,fcfb5) 91 | __PF(FCFABRIC+6,fcfb6) 92 | __PF(FCFABRIC+7,fcfb7) 93 | __PF(FCFABRIC+8,fcfb8) 94 | __PF(FCFABRIC+9,fcfb9) 95 | __PF(FCFABRIC+10,fcfb10) 96 | __PF(FCFABRIC+11,fcfb11) 97 | __PF(FCFABRIC+12,fcfb12) 98 | __PF(IEEE802_TR,tr) 99 | __PF(IEEE80211,ieee802.11) 100 | __PF(IEEE80211_PRISM,ieee802.11/prism) 101 | __PF(IEEE80211_RADIOTAP,ieee802.11/radiotap) 102 | __PF(IEEE802154, ieee802.15.4) 103 | __PF(PHONET, phonet) 104 | __PF(PHONET_PIPE, phonet_pipe) 105 | __PF(CAIF, caif) 106 | 107 | __PF(NONE, none) 108 | __PF(VOID,void) 109 | }; 110 | #undef __PF 111 | 112 | int i; 113 | for (i=0; i<sizeof(arphrd_names)/sizeof(arphrd_names[0]); i++) { 114 | if (arphrd_names[i].type == type) 115 | return arphrd_names[i].name; 116 | } 117 | snprintf(buf, len, "[%d]", type); 118 | return buf; 119 | } 120 | -------------------------------------------------------------------------------- /tc/q_drr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * q_drr.c DRR. 3 | * 4 | * This program is free software; you can redistribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Patrick McHardy <kaber@trash.net> 10 | * 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include <unistd.h> 16 | #include <syslog.h> 17 | #include <fcntl.h> 18 | #include <sys/socket.h> 19 | #include <netinet/in.h> 20 | #include <arpa/inet.h> 21 | #include <string.h> 22 | 23 | #include "utils.h" 24 | #include "tc_util.h" 25 | 26 | static void explain(void) 27 | { 28 | fprintf(stderr, "Usage: ... drr\n"); 29 | } 30 | 31 | static void explain2(void) 32 | { 33 | fprintf(stderr, "Usage: ... drr quantum SIZE\n"); 34 | } 35 | 36 | 37 | static int drr_parse_opt(struct qdisc_util *qu, int argc, char **argv, struct nlmsghdr *n) 38 | { 39 | while (argc) { 40 | if (strcmp(*argv, "help") == 0) { 41 | explain(); 42 | return -1; 43 | } else { 44 | fprintf(stderr, "What is \"%s\"?\n", *argv); 45 | explain(); 46 | return -1; 47 | } 48 | } 49 | return 0; 50 | } 51 | 52 | static int drr_parse_class_opt(struct qdisc_util *qu, int argc, char **argv, 53 | struct nlmsghdr *n) 54 | { 55 | struct rtattr *tail; 56 | __u32 tmp; 57 | 58 | tail = NLMSG_TAIL(n); 59 | addattr_l(n, 1024, TCA_OPTIONS, NULL, 0); 60 | 61 | while (argc > 0) { 62 | if (strcmp(*argv, "quantum") == 0) { 63 | NEXT_ARG(); 64 | if (get_size(&tmp, *argv)) { 65 | fprintf(stderr, "Illegal \"quantum\"\n"); 66 | return -1; 67 | } 68 | addattr_l(n, 1024, TCA_DRR_QUANTUM, &tmp, sizeof(tmp)); 69 | } else if (strcmp(*argv, "help") == 0) { 70 | explain2(); 71 | return -1; 72 | } else { 73 | fprintf(stderr, "What is \"%s\"?\n", *argv); 74 | explain2(); 75 | return -1; 76 | } 77 | argc--; argv++; 78 | } 79 | 80 | tail->rta_len = (void *) NLMSG_TAIL(n) - (void *)tail; 81 | return 0; 82 | } 83 | 84 | static int drr_print_opt(struct qdisc_util *qu, FILE *f, struct rtattr *opt) 85 | { 86 | struct rtattr *tb[TCA_DRR_MAX + 1]; 87 | SPRINT_BUF(b1); 88 | 89 | if (opt == NULL) 90 | return 0; 91 | 92 | parse_rtattr_nested(tb, TCA_DRR_MAX, opt); 93 | 94 | if (tb[TCA_DRR_QUANTUM]) 95 | fprintf(f, "quantum %s ", 96 | sprint_size(rta_getattr_u32(tb[TCA_DRR_QUANTUM]), b1)); 97 | return 0; 98 | } 99 | 100 | static int drr_print_xstats(struct qdisc_util *qu, FILE *f, struct rtattr *xstats) 101 | { 102 | struct tc_drr_stats *x; 103 | SPRINT_BUF(b1); 104 | 105 | if (xstats == NULL) 106 | return 0; 107 | if (RTA_PAYLOAD(xstats) < sizeof(*x)) 108 | return -1; 109 | x = RTA_DATA(xstats); 110 | 111 | fprintf(f, " deficit %s ", sprint_size(x->deficit, b1)); 112 | return 0; 113 | } 114 | 115 | struct qdisc_util drr_qdisc_util = { 116 | .id = "drr", 117 | .parse_qopt = drr_parse_opt, 118 | .print_qopt = drr_print_opt, 119 | .print_xstats = drr_print_xstats, 120 | .parse_copt = drr_parse_class_opt, 121 | .print_copt = drr_print_opt, 122 | }; 123 | -------------------------------------------------------------------------------- /tc/f_cgroup.c: -------------------------------------------------------------------------------- 1 | /* 2 | * f_cgroup.c Control Group Classifier 3 | * 4 | * This program is free software; you can distribute it and/or 5 | * modify it under the terms of the GNU General Public License 6 | * as published by the Free Software Foundation; either version 7 | * 2 of the License, or (at your option) any later version. 8 | * 9 | * Authors: Thomas Graf <tgraf@infradead.org> 10 | * 11 | */ 12 | 13 | #include <stdio.h> 14 | #include <stdlib.h> 15 | #include "utils.h" 16 | #include "tc_util.h" 17 | #include "m_ematch.h" 18 | 19 | static void explain(void) 20 | { 21 | fprintf(stderr, "Usage: ... cgroup [ match EMATCH_TREE ] [ police POLICE_SPEC ]\n"); 22 | fprintf(stderr, " [ action ACTION_SPEC ]\n"); 23 | } 24 | 25 | static int cgroup_parse_opt(struct filter_util *qu, char *handle, 26 | int argc, char **argv, struct nlmsghdr *n) 27 | { 28 | struct tcmsg *t = NLMSG_DATA(n); 29 | struct rtattr *tail; 30 | long h = 0; 31 | 32 | if (handle) { 33 | h = strtol(handle, NULL, 0); 34 | if (h == LONG_MIN || h == LONG_MAX) { 35 | fprintf(stderr, "Illegal handle \"%s\", must be numeric.\n", 36 | handle); 37 | return -1; 38 | } 39 | } 40 | 41 | t->tcm_handle = h; 42 | 43 | tail = (struct rtattr*)(((void*)n)+NLMSG_ALIGN(n->nlmsg_len)); 44 | addattr_l(n, MAX_MSG, TCA_OPTIONS, NULL, 0); 45 | 46 | while (argc > 0) { 47 | if (matches(*argv, "match") == 0) { 48 | NEXT_ARG(); 49 | if (parse_ematch(&argc, &argv, TCA_CGROUP_EMATCHES, n)) { 50 | fprintf(stderr, "Illegal \"ematch\"\n"); 51 | return -1; 52 | } 53 | continue; 54 | } else if (matches(*argv, "action") == 0) { 55 | NEXT_ARG(); 56 | if (parse_action(&argc, &argv, TCA_CGROUP_ACT, n)) { 57 | fprintf(stderr, "Illegal \"action\"\n"); 58 | return -1; 59 | } 60 | continue; 61 | 62 | } else if (matches(*argv, "police") == 0) { 63 | NEXT_ARG(); 64 | if (parse_police(&argc, &argv, TCA_CGROUP_POLICE, n)) { 65 | fprintf(stderr, "Illegal \"police\"\n"); 66 | return -1; 67 | } 68 | continue; 69 | } else if (strcmp(*argv, "help") == 0) { 70 | explain(); 71 | return -1; 72 | } else { 73 | fprintf(stderr, "What is \"%s\"?\n", *argv); 74 | explain(); 75 | return -1; 76 | } 77 | } 78 | 79 | tail->rta_len = (((void*)n)+n->nlmsg_len) - (void*)tail; 80 | return 0; 81 | } 82 | 83 | static int cgroup_print_opt(struct filter_util *qu, FILE *f, 84 | struct rtattr *opt, __u32 handle) 85 | { 86 | struct rtattr *tb[TCA_CGROUP_MAX+1]; 87 | 88 | if (opt == NULL) 89 | return 0; 90 | 91 | parse_rtattr_nested(tb, TCA_CGROUP_MAX, opt); 92 | 93 | if (handle) 94 | fprintf(f, "handle 0x%x ", handle); 95 | 96 | if (tb[TCA_CGROUP_EMATCHES]) 97 | print_ematch(f, tb[TCA_CGROUP_EMATCHES]); 98 | 99 | if (tb[TCA_CGROUP_POLICE]) { 100 | fprintf(f, "\n"); 101 | tc_print_police(f, tb[TCA_CGROUP_POLICE]); 102 | } 103 | 104 | if (tb[TCA_CGROUP_ACT]) 105 | tc_print_action(f, tb[TCA_CGROUP_ACT]); 106 | 107 | return 0; 108 | } 109 | 110 | struct filter_util cgroup_filter_util = { 111 | .id = "cgroup", 112 | .parse_fopt = cgroup_parse_opt, 113 | .print_fopt = cgroup_print_opt, 114 | }; 115 | --------------------------------------------------------------------------------