centralize the code to free a packet (or a chain) while in dummynet.
Remove an old macro and its stale comment.
This commit is contained in:
parent
71c74ac313
commit
1ac82bf52a
@ -460,6 +460,27 @@ heap_free(struct dn_heap *h)
|
|||||||
* --- end of heap management functions ---
|
* --- end of heap management functions ---
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Dispose a packet in dummynet. Use an inline functions so if we
|
||||||
|
* need to free extra state associated to a packet, this is a
|
||||||
|
* central point to do it.
|
||||||
|
*/
|
||||||
|
static __inline void *dn_free_pkt(struct mbuf *m)
|
||||||
|
{
|
||||||
|
m_freem(m);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static __inline void dn_free_pkts(struct mbuf *mnext)
|
||||||
|
{
|
||||||
|
struct mbuf *m;
|
||||||
|
|
||||||
|
while ((m = mnext) != NULL) {
|
||||||
|
mnext = m->m_nextpkt;
|
||||||
|
dn_free_pkt(m);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return the mbuf tag holding the dummynet state. As an optimization
|
* Return the mbuf tag holding the dummynet state. As an optimization
|
||||||
* this is assumed to be the first tag on the list. If this turns out
|
* this is assumed to be the first tag on the list. If this turns out
|
||||||
@ -1009,12 +1030,12 @@ dummynet_send(struct mbuf *m)
|
|||||||
|
|
||||||
case DN_TO_DROP:
|
case DN_TO_DROP:
|
||||||
/* drop the packet after some time */
|
/* drop the packet after some time */
|
||||||
m_freem(m);
|
dn_free_pkt(m);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
printf("dummynet: bad switch %d!\n", pkt->dn_dir);
|
printf("dummynet: bad switch %d!\n", pkt->dn_dir);
|
||||||
m_freem(m);
|
dn_free_pkt(m);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1553,19 +1574,10 @@ dropit:
|
|||||||
if (q)
|
if (q)
|
||||||
q->drops++;
|
q->drops++;
|
||||||
DUMMYNET_UNLOCK();
|
DUMMYNET_UNLOCK();
|
||||||
m_freem(m);
|
*m0 = dn_free_pkt(m);
|
||||||
*m0 = NULL;
|
|
||||||
return ((fs && (fs->flags_fs & DN_NOERROR)) ? 0 : ENOBUFS);
|
return ((fs && (fs->flags_fs & DN_NOERROR)) ? 0 : ENOBUFS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Below, the rt_unref is only needed when (pkt->dn_dir == DN_TO_IP_OUT)
|
|
||||||
* Doing this would probably save us the initial bzero of dn_pkt
|
|
||||||
*/
|
|
||||||
#define DN_FREE_PKT(_m) do { \
|
|
||||||
m_freem(_m); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dispose all packets and flow_queues on a flow_set.
|
* Dispose all packets and flow_queues on a flow_set.
|
||||||
* If all=1, also remove red lookup table and other storage,
|
* If all=1, also remove red lookup table and other storage,
|
||||||
@ -1582,13 +1594,7 @@ purge_flow_set(struct dn_flow_set *fs, int all)
|
|||||||
|
|
||||||
for (i = 0; i <= fs->rq_size; i++) {
|
for (i = 0; i <= fs->rq_size; i++) {
|
||||||
for (q = fs->rq[i]; q != NULL; q = qn) {
|
for (q = fs->rq[i]; q != NULL; q = qn) {
|
||||||
struct mbuf *m, *mnext;
|
dn_free_pkts(q->head);
|
||||||
|
|
||||||
mnext = q->head;
|
|
||||||
while ((m = mnext) != NULL) {
|
|
||||||
mnext = m->m_nextpkt;
|
|
||||||
DN_FREE_PKT(m);
|
|
||||||
}
|
|
||||||
qn = q->next;
|
qn = q->next;
|
||||||
free(q, M_DUMMYNET);
|
free(q, M_DUMMYNET);
|
||||||
}
|
}
|
||||||
@ -1616,15 +1622,10 @@ purge_flow_set(struct dn_flow_set *fs, int all)
|
|||||||
static void
|
static void
|
||||||
purge_pipe(struct dn_pipe *pipe)
|
purge_pipe(struct dn_pipe *pipe)
|
||||||
{
|
{
|
||||||
struct mbuf *m, *mnext;
|
|
||||||
|
|
||||||
purge_flow_set( &(pipe->fs), 1 );
|
purge_flow_set( &(pipe->fs), 1 );
|
||||||
|
|
||||||
mnext = pipe->head;
|
dn_free_pkts(pipe->head);
|
||||||
while ((m = mnext) != NULL) {
|
|
||||||
mnext = m->m_nextpkt;
|
|
||||||
DN_FREE_PKT(m);
|
|
||||||
}
|
|
||||||
|
|
||||||
heap_free( &(pipe->scheduler_heap) );
|
heap_free( &(pipe->scheduler_heap) );
|
||||||
heap_free( &(pipe->not_eligible_heap) );
|
heap_free( &(pipe->not_eligible_heap) );
|
||||||
@ -1974,7 +1975,6 @@ dummynet_drain(void)
|
|||||||
{
|
{
|
||||||
struct dn_flow_set *fs;
|
struct dn_flow_set *fs;
|
||||||
struct dn_pipe *pipe;
|
struct dn_pipe *pipe;
|
||||||
struct mbuf *m, *mnext;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
DUMMYNET_LOCK_ASSERT();
|
DUMMYNET_LOCK_ASSERT();
|
||||||
@ -1990,12 +1990,7 @@ dummynet_drain(void)
|
|||||||
for (i = 0; i < HASHSIZE; i++) {
|
for (i = 0; i < HASHSIZE; i++) {
|
||||||
SLIST_FOREACH(pipe, &pipehash[i], next) {
|
SLIST_FOREACH(pipe, &pipehash[i], next) {
|
||||||
purge_flow_set(&(pipe->fs), 0);
|
purge_flow_set(&(pipe->fs), 0);
|
||||||
|
dn_free_pkt(pipe->head);
|
||||||
mnext = pipe->head;
|
|
||||||
while ((m = mnext) != NULL) {
|
|
||||||
mnext = m->m_nextpkt;
|
|
||||||
DN_FREE_PKT(m);
|
|
||||||
}
|
|
||||||
pipe->head = pipe->tail = NULL;
|
pipe->head = pipe->tail = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user