Fragman preserves packet header
This commit is contained in:
parent
059c0e542e
commit
cc257ed27f
@ -54,6 +54,7 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "capwap.h"
|
#include "capwap.h"
|
||||||
|
#include "cw.h"
|
||||||
#include "fragman.h"
|
#include "fragman.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -101,20 +102,6 @@ static struct frag * frag_new(struct frag * frags, int fragid)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
void fragman_free(frag_t * frags,struct frag * f)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
for (i=0; i<FRAG_MAXIDS; i++){
|
|
||||||
if (frags[i]->fragid==f->fragid){
|
|
||||||
frags[i]=NULL;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(f);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a fragment
|
* Add a fragment
|
||||||
* @pram frags Fragman object
|
* @pram frags Fragman object
|
||||||
@ -129,12 +116,10 @@ uint8_t * fragman_add(frag_t * frags, uint8_t *packet, int hlen, int payloadlen)
|
|||||||
uint32_t val0,val1;
|
uint32_t val0,val1;
|
||||||
int fragid,fragoffset;
|
int fragid,fragoffset;
|
||||||
int dst;
|
int dst;
|
||||||
int ti;
|
|
||||||
|
|
||||||
/* read the transport header dword 0,
|
/* read the transport header dword 0,
|
||||||
* contains hlen*/
|
* contains hlen*/
|
||||||
val0 = ntohl(*((uint32_t*)packet));
|
val0 = ntohl(*((uint32_t*)packet));
|
||||||
/* int hlen = (val0 >> 19) & 0x1f;*/
|
|
||||||
|
|
||||||
/* read the transport header dword 1,
|
/* read the transport header dword 1,
|
||||||
* contains fragid and fragoffset */
|
* contains fragid and fragoffset */
|
||||||
@ -142,33 +127,30 @@ uint8_t * fragman_add(frag_t * frags, uint8_t *packet, int hlen, int payloadlen)
|
|||||||
fragid = val1>>16;
|
fragid = val1>>16;
|
||||||
fragoffset=(val1 >>3) & 0x1fff;
|
fragoffset=(val1 >>3) & 0x1fff;
|
||||||
|
|
||||||
/*// printf("Fragid = %i, offset = %i\n",fragid,fragoffset);*/
|
|
||||||
|
|
||||||
/* determine size of payload */
|
|
||||||
/* int payloadlen = len - hlen*4;
|
|
||||||
if (payloadlen<0){
|
|
||||||
errno = EINVAL;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
/* find / create cfragment */
|
/* find / create cfragment */
|
||||||
f = frag_get(frags,fragid);
|
f = frag_get(frags,fragid);
|
||||||
if (!f){
|
if (!f){
|
||||||
f = frag_new(frags,fragid);
|
f = frag_new(frags,fragid);
|
||||||
}
|
|
||||||
if (!f){
|
if (!f){
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
/* out of fragmentation space */
|
/* out of fragmentation space */
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
errno = 0;
|
errno = 0;
|
||||||
|
|
||||||
dst = fragoffset*8;
|
dst = fragoffset*8;
|
||||||
|
|
||||||
/* copy fragment*/
|
/* copy fragment*/
|
||||||
if (dst + payloadlen < FRAG_MAXSIZE) {
|
if (dst + payloadlen < FRAG_MAXSIZE) {
|
||||||
memcpy( f->buffer+4+dst,packet+hlen,payloadlen);
|
if (fragoffset==0){
|
||||||
|
/* preserve header of 1st fragment */
|
||||||
|
memset(f->buffer,0,MAX_PKT_HDR_LEN);
|
||||||
|
memcpy(f->buffer,packet,hlen);
|
||||||
|
cw_set_hdr_hlen(f->buffer,MAX_PKT_HDR_LEN/4);
|
||||||
|
cw_set_hdr_flags(f->buffer, CAPWAP_FLAG_HDR_F, 0);
|
||||||
|
}
|
||||||
|
memcpy( f->buffer+MAX_PKT_HDR_LEN+4+dst,packet+hlen,payloadlen);
|
||||||
f->bytesreceived+=payloadlen;
|
f->bytesreceived+=payloadlen;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,21 +159,13 @@ uint8_t * fragman_add(frag_t * frags, uint8_t *packet, int hlen, int payloadlen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (ti=0; ti<16; ti++){
|
|
||||||
/*// printf("%02X ",(f->buffer+4)[ti]);*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (f->bytesneeded>0 && f->bytesneeded<=f->bytesreceived){
|
if (f->bytesneeded>0 && f->bytesneeded<=f->bytesreceived){
|
||||||
uint8_t * r=f->buffer;
|
uint8_t * r=f->buffer;
|
||||||
f->buffer=0;
|
f->buffer=0;
|
||||||
/*// printf("last bytes need %i\n",f->bytesneeded);*/
|
*((uint32_t*)(r+MAX_PKT_HDR_LEN))=f->bytesneeded;
|
||||||
*((uint32_t*)(r))=f->bytesneeded;
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*// printf("Fragman bytes needed: %i, received %i\n",f->bytesneeded,f->bytesreceived);*/
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*@defgroup Fragman FRAGMAN
|
*@defgroup Fragman FRAGMAN
|
||||||
*@breif Frgaman functions
|
*@brief Frgaman functions
|
||||||
*
|
*
|
||||||
* Detailed esription
|
* Detailed desription
|
||||||
*@{
|
*@{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -33,18 +33,18 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifndef FRAG_MAXSIZE
|
|
||||||
/** maximaum size of a fragment */
|
|
||||||
#define FRAG_MAXSIZE (65536+4)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef FRAG_MAXIDS
|
#define MAX_PKT_HDR_LEN 64
|
||||||
#define FRAG_MAXIDS 10
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef FRAG_TTL
|
/** maximaum size of a fragment */
|
||||||
#define FRAG_TTL 5
|
#define FRAG_MAXSIZE (65536+MAX_PKT_HDR_LEN)
|
||||||
#endif
|
|
||||||
|
#define FRAG_MAXIDS 10
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TTL of received fragment in seconds
|
||||||
|
*/
|
||||||
|
#define FRAG_TTL 5
|
||||||
|
|
||||||
|
|
||||||
struct frag {
|
struct frag {
|
||||||
@ -57,7 +57,7 @@ struct frag {
|
|||||||
int bytesreceived;
|
int bytesreceived;
|
||||||
int bytesneeded;
|
int bytesneeded;
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
uint8_t * header;
|
// uint8_t * header;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct frag frag_t; /*FRAGMAN;*/
|
typedef struct frag frag_t; /*FRAGMAN;*/
|
||||||
|
Loading…
Reference in New Issue
Block a user