只需要修改iproute2应用层的makefile就可以了,编译tc并把tc拷贝到执行目录里
② linux中nat+tc怎么做
用linux做nat服务,用tc限制流量 作者:用linux做nat服务,用tc限制流量 最近有同事用bt和电驴疯狂下载,我们上网打cs受到极大影响,所以对nat上网做了流量控制,将一点经验介绍给网友,希望对cs fans 有所帮助. 我们上网环境如下: eth0 外网ip :a.b.c.d eth1 内网ip1:192.168.0.0/24 给老板和bt eth2 内网ip2:192.168.1.0/24 给我和csfans 用linux 做nat 命令如下: echo 1 > /proc/sys/net/ipv4/ip_forward iptables -F iptables -t nat -F ----清除旧规则 iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -o eth0 -j SNAT --to a.b.c.d ---为内网ip1 做nat iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j SNAT -- to a.b.c.d ---为内网ip2 做nat ------------为流量控制做基于fw过滤器的标记 iptables -I PREROUTING -t mangle -p tcp -s 192.168.0.0/24 -j MARK --set-mark 1 iptables -I PREROUTING -t mangle -p tcp -s 192.168.1.0/24 -j MARK --set-mark 2 ------------为上传速率做流量控制 tc 要求内核2.4.18以上,所以不够的要升级 tc 只能控制网卡发送包的速率,所以上传速率的限制要在eth0上做 ----删除旧有队列
③ 求解TC小型计算器C语言源代码
#include<stdio.h>
main()
{
int a,b;
char ch;
printf("请输入表达式如:1+2 \n");
scanf("%d%c%d",&a,&ch,&b);
if(ch=='/' && b==0)
printf("被除数为0请检查表达式是否出错?");
else
{ switch(ch)
{
case '+': printf("%d+%d=%d\n",a,b,a+b);break;
case '-': printf("%d-%d=%d\n",a,b,a-b);break;
case '*': printf("%d*%d=%d\n",a,b,a*b);break;
case '/': printf("%d/%d=%d\n",a,b,a/b);break;
}
}
}
④ Linux下带宽限制命令TC
用iptables 试试,应该比tc简单吧
⑤ 如何通过TC实现基于Linux系统的流量管理
接收包从输入接口(Input Interface)进来后,经过流量限制(Ingress Policing)丢弃不符合规定的数据包,由输入多路分配器(Input De-Multiplexing)进行判断选择:如果接收包的目的是本主机,那么将该包送给上层处理;否则需要进行转发,将接收包交到转发块(Forwarding Block)处理。转发块同时也接收本主机上层(TCP、UDP等)产生的包。转发块通过查看路由表,决定所处理包的下一跳。然后,对包进行排列以便将它们传送到输出接口(Output Interface)。一般我们只能限制网卡发送的数据包,不能限制网卡接收的数据包,所以我们可以通过改变发送次序来控制传输速率。Linux流量控制主要是在输出接口排列时进行处理和实现的。
⑥ linux qos 源码在哪个文件
关于代码实现,首先要说的是在帧的接收和发送的时候都讲到了qos. 在实际的应用中发送用的最多,而接收的控制需要其他辅助性的工作. linux下qos需要iproute2集成的tc命令,以及iptables命令等的支持和配合,它和iptables/netfilters有点类似都需要用户空间和内核空间的配合.
QOS的控制分为Ingress 和Egress。这里主要分析出口.
调试需要iproute2的tc :
点击(此处)折叠或打开
Linux Traffic Control is configured with the utility tc. It is part of the iproute2 package. Some Linux distributions already include tc, but it may be an old version, without support for Diffserv.
点击(此处)折叠或打开
调试版本iproute2-4.2.0
那么编译iproute2需要依赖的东西:
Bison
Flex
Libdb-dev
找到tc的源码后,我们先看看tc命令的主程序 tc.c
点击(此处)折叠或打开
int main(int argc, char **argv)
{
int ret;
char *batch_file = NULL;
while (argc > 1) {
if (argv[1][0] != '-')
break;
if (matches(argv[1], "-stats") == 0 ||
matches(argv[1], "-statistics") == 0) {
++show_stats;
} else if (matches(argv[1], "-details") == 0) {
++show_details;
} else if (matches(argv[1], "-raw") == 0) {
++show_raw;
} else if (matches(argv[1], "-pretty") == 0) {
++show_pretty;
} else if (matches(argv[1], "-graph") == 0) {
show_graph = 1;
} else if (matches(argv[1], "-Version") == 0) {
printf("tc utility, iproute2-ss%s\n", SNAPSHOT);
return 0;
} else if (matches(argv[1], "-iec") == 0) {
++use_iec;
} else if (matches(argv[1], "-help") == 0) {
usage();
return 0;
} else if (matches(argv[1], "-force") == 0) {
++force;
} else if (matches(argv[1], "-batch") == 0) {
argc--; argv++;
if (argc <= 1)
usage();
batch_file = argv[1];
} else if (matches(argv[1], "-netns") == 0) {
NEXT_ARG();
if (netns_switch(argv[1]))
return -1;
} else if (matches(argv[1], "-names") == 0 ||
matches(argv[1], "-nm") == 0) {
use_names = true;
} else if (matches(argv[1], "-cf") == 0 ||
matches(argv[1], "-conf") == 0) {
NEXT_ARG();
conf_file = argv[1];
} else {
fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
return -1;
}
argc--; argv++;
}
if (batch_file)
return batch(batch_file);
if (argc <= 1) {
usage();
return 0;
}
tc_core_init();
if (rtnl_open(&rth, 0) < 0) {
fprintf(stderr, "Cannot open rtnetlink\n");
exit(1);
}
if (use_names && cls_names_init(conf_file)) {
ret = -1;
goto Exit;
}
ret = do_cmd(argc-1, argv+1);
Exit:
rtnl_close(&rth);
if (use_names)
cls_names_uninit();
return ret;
}
⑦ 求tc 下的多边形裁剪算法的源代码
#include <graphics.h>
#include <dos.h>
union REGS i,o;
int xl=100,xr=540,yb=400,yt=200; /*方框边界*/
void init()
{
int driver=DETECT,gm;
initgraph(&driver,&gm,"");
printf("Instruction:\n");
printf("1.Press left mouse button to set the vertex;\n");
printf("2.Press right button to end drawing;\n");
/*printf("3.Press both button to clip.");*/
outtextxy(450, 440, "Edit by lcf&hy!");
setwritemode(2);
line(0,70,639,70);
setcolor(YELLOW);
rectangle(xl,yt,xr,yb);
i.x.ax=0;
int86(0x33,&i,&o);
if(o.x.ax==0)
{
printf("Mouse is not available...");
getch();
exit();
}
i.x.ax=1;
int86(0x33,&i,&o);
/*设置光标可用范围(Y方向)*/
i.x.ax=8;
i.x.cx=71;
i.x.dx=479;
int86(0x33,&i,&o);
}
int mousestatus(int *x,int *y)
{
i.x.ax=3; /*查询鼠标状态功能号为03H*/
int86(0x33,&i,&o);
*x=o.x.cx; /*鼠标横坐标 */
*y=o.x.dx; /*鼠标纵坐标 */
return o.x.bx; /*返回按键情况:0-NONE,1-LEFT,2-RIGHT,3-BOTH; */
}
void endpro() /*结束裁剪*/
{
char s[50]="Press any key to exit...";
setcolor(WHITE);
outtextxy(200,120,s); /*此处有可能出现乱码,正常现象,出现概率随机*/
getch();
closegraph();
exit();
}
void code(int x,int y,int *c )
{/*c为5元数组*/
int i;
for(i=1;i<=4;i++) c[i]=0;
if(x<xl) c[4]=1;
if(x>xr) c[3]=1;
if(y<yt) c[1]=1;
if(y>yb) c[2]=1;
}
void cut(int x1,int y1,int x2,int y2)/*把不需要的线置为黑色,不可见*/
{
setcolor(BLACK);
setlinestyle(0, 0, 3); /*设置三点宽实线*/
line(x1,y1,x2,y2);
}
int logic_ride(int *c1,int *c2)/*判断逻辑乘是否为0,是则返回0,否则返回1*/
{
int i;
for(i=1;i<=4;i++)
{
if(c1[i]*c2[i]==1) return 1;
}
return 0;
}
int logic2_ride(int *c)/*在内部则返回1,否则返回0*/
{
int m;
for(m=0;m<=4;m++)
if(c[m]==1) return 0;
return 1;
}
void clip(int *x,int *y,int k)
/*裁剪函数,如果某个线段不在可视区,我们将其颜色置为黑色,否则不作颜色改变*/
{
/*int i;
for(i=1;i<=k;i++)
printf("%d,%d\n",x[i],y[i]);*/ /*此段代码检测模板存入的数据没错*/
int c1[5],c2[5],c[5],p,x0,y0,ultra_x,ultra_y,t;/*x0,y0储存临时交点*/
x[k+1]=x[1];y[k+1]=y[1];
for(p=1;p<=k;p++)
{
code(x[p],y[p],c1);
code(x[p+1],y[p+1],c2);
if(logic_ride(c1,c2)) cut(x[p],y[p],x[p+1],y[p+1]);/*完全不可见,则完全剪除*/
else if(logic2_ride(c1)==1&&logic2_ride(c2)==1) ;/*排除一种情况*/
else /*不完全在里面,也不完全在外面*/
{
if(logic2_ride(c1)!=1)/*起点在外面*/
{
t=1;
while(t)
{
if(logic_ride(c,c2)) {cut(x[p],y[p],x[p+1],y[p+1]);break;}/*完全不可见,则完全剪除*/
else
{
if(c1[4]==1)/*判断四边的情况*/
{
x0=xl;
y0=y[p]+(y[p+1]-y[p])*(xl-x[p])/(x[p+1]-x[p]);
}
else if(c1[3]==1)
{
x0=xr;
y0=y[p]+(y[p+1]-y[p])*(xr-x[p])/(x[p+1]-x[p]);
}
else if(c1[1]==1)
{
y0=yt;
x0=x[p]+(x[p+1]-x[p])*(yt-y[p])/(y[p+1]-y[p]);
}
else if(c1[2]==1)
{
y0=yb;
x0=x[p]+(x[p+1]-x[p])*(yb-y[p])/(y[p+1]-y[p]);
}
cut(x[p],y[p],x0,y0);
x[p]=x0;y[p]=y0; code(x0,y0,c);
if(logic2_ride(c)==1) t=0;
}
}
}
if(logic2_ride(c2)!=1)/*终点在外面*/
{
t=1;
if(c2[4]==1)/*判断四边的情况*/
{
x0=xl;
y0=y[p]+(y[p+1]-y[p])*(xl-x[p])/(x[p+1]-x[p]);
}
else if(c2[3]==1)
{
x0=xr;
y0=y[p]+(y[p+1]-y[p])*(xr-x[p])/(x[p+1]-x[p]);
}
else if(c2[1]==1)
{
y0=yt; x0=x[p]+(x[p+1]-x[p])*(yt-y[p])/(y[p+1]-y[p]);
}
else if(c2[2]==1)
{
y0=yb; x0=x[p]+(x[p+1]-x[p])*(yb-y[p])/(y[p+1]-y[p]);
}
cut(x0,y0,x[p+1],y[p+1]);
code(x0,y0,c);
if(logic2_ride(c)==0)
{
if(c[4]==1)/*判断四边的情况*/
{
ultra_x=xl;
ultra_y=y0+(y[p+1]-y0)*(xl-x0)/(x[p+1]-x0);
}
else if(c[3]==1)
{
ultra_x=xr;
ultra_y=y0+(y[p+1]-0)*(xr-0)/(x[p+1]-x0);
}
else if(c[1]==1)
{
ultra_y=yt;
ultra_x=x0+(x[p+1]-x0)*(yt-y0)/(y[p+1]-y0);
}
else if(c[2]==1)
{
ultra_y=yb;
ultra_x=x0+(x[p+1]-x0)*(yb-y0)/(y[p+1]-y0);
}
cut(x0,y0,ultra_x,ultra_y);
}
}
}
}
endpro();
}
void draw(int *x,int *y)
{
int k=0,lx,ly,color,i;
int tempx,tempy;
while(1){
/*描点并存储顶点*/
if(mousestatus(&tempx,&tempy)==1)
{
if(x[k]!=tempx||y[k]!=tempy) k++; /*这一步有关键,想想看为什么?*/
x[k]=tempx;
y[k]=tempy;
setcolor(WHITE);
circle(tempx,tempy,1);
if (k!=1)
{
setcolor(WHITE);
line(x[k-1],y[k-1],x[k],y[k]);
}
}
lx=tempx,ly=tempy;
if(mousestatus(&tempx,&tempy)==2) /*如果按下右键*/
{
line(x[1],y[1],x[k],y[k]);
clip(x,y,k);
}
putpixel(tempx,tempy,WHITE);/* trace the mouse,*/
putpixel(lx,ly,BLACK);
}
}
void main()
{
int x[100],y[100];
init();
draw(x,y);
}
⑧ 谁有TC源代码
这东西应该没有的吧,人家还要靠他赚钱呢,不可能开放源代码给你的
------淡淡仙恋------
⑨ linux tc 命令
希望下列网页对你有帮助
英文man:
http://linux.die.net/man/8/tc
中文man:
http://hi..com/chuanqi_ding/blog/item/862836826ba2d6a70cf4d253.html
你也可以 man tc 获取联机帮助,内容与上面类似。