3 * Usage: tc set <dev> pfifo limit <packets>
12 #include <vdecommon.h>
16 /** Private per-interface structure
26 #define pfifo_tcpriv(x) (struct tc_pfifo*)(tcpriv(x))
29 * Enqueue function. Try to add the packet 'vdb' to the output queue
30 * of the interface 'vif'
32 * return value: 1 = packet was enqueued, 0 = packet was rejected
34 int pfifo_enqueue(struct vde_buff
*vdb
, struct vde_iface
*vif
)
36 struct tc_pfifo
*pfifo
= pfifo_tcpriv(vif
);
37 if (pfifo
->qlen
< pfifo
->limit
){
39 ufifo_enqueue(vdb
,vif
);
42 /* Queue Full: dropping. */
49 /* Dequeue function. Interface is ready to send the packet.
52 int pfifo_dequeue(struct vde_iface
*vif
)
54 struct tc_pfifo
*pfifo
= pfifo_tcpriv(vif
);
55 (void)ufifo_dequeue(vif
);
58 return (pfifo
->qlen
> 0);
63 /* Function to initialize the queue on the given interface.
65 int pfifo_init(struct vde_iface
*vif
, char *args
)
67 struct tc_pfifo
*pfifo
=(struct tc_pfifo
*)malloc(sizeof(struct tc_pfifo
));
68 int arglen
= strlen(args
) - 1;
70 if ((arglen
< 6) || strncmp(args
,"limit ",6) || (sscanf(args
+6, "%u",&(pfifo
->limit
)) < 1) )
75 vif
->policy_name
="pfifo";
76 memcpy(vif
->tc_priv
, pfifo
, sizeof(struct tc_pfifo
));
80 char *pfifo_tc_stats(struct vde_iface
*vif
)
82 struct tc_pfifo
*pfifo
= pfifo_tcpriv(vif
);
83 char *statistics
=(char*)malloc(256);
84 snprintf(statistics
,255,"Limit: %u packets. Dropped: %u packets.", pfifo
->limit
, pfifo
->dropped
);
91 * Module symbol to load into module list.
94 struct routing_policy module_routing_policy
=
97 .help
="Packet Fifo queue\nUsage: tc set <dev> pfifo limit <packets>\n",
98 .policy_init
= pfifo_init
,
99 .enqueue
= pfifo_enqueue
,
100 .dequeue
= pfifo_dequeue
,
101 .tc_stats
= pfifo_tc_stats
105 __attribute__ ((constructor
))
108 fprintf(stderr
,"Loading library: pfifo.so\n");
113 __attribute__ ((destructor
))