2005-11-04 16:27:45 +00:00
|
|
|
/*
|
2012-02-24 10:42:32 +00:00
|
|
|
* Copyright (C) 2012 Tobias Brunner
|
2006-07-07 08:49:06 +00:00
|
|
|
* Copyright (C) 2005-2006 Martin Willi
|
|
|
|
* Copyright (C) 2005 Jan Hutter
|
2018-05-23 14:04:50 +00:00
|
|
|
* HSR Hochschule fuer Technik Rapperswil
|
2005-11-04 16:27:45 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
2008-03-13 14:14:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @defgroup packet packet
|
2012-10-16 12:33:28 +00:00
|
|
|
* @{ @ingroup networking
|
2005-11-04 16:27:45 +00:00
|
|
|
*/
|
2006-10-30 14:07:05 +00:00
|
|
|
|
2005-11-04 16:27:45 +00:00
|
|
|
#ifndef PACKET_H_
|
|
|
|
#define PACKET_H_
|
|
|
|
|
2006-10-30 14:07:05 +00:00
|
|
|
typedef struct packet_t packet_t;
|
2005-11-04 16:27:45 +00:00
|
|
|
|
2006-10-31 12:27:59 +00:00
|
|
|
#include <library.h>
|
2012-10-16 12:29:18 +00:00
|
|
|
#include <networking/host.h>
|
2005-11-04 16:27:45 +00:00
|
|
|
|
2014-09-16 13:38:38 +00:00
|
|
|
/**
|
|
|
|
* Maximum packet size we handle by default
|
|
|
|
*/
|
|
|
|
#define PACKET_MAX_DEFAULT 10000
|
|
|
|
|
2005-11-04 16:27:45 +00:00
|
|
|
/**
|
2012-07-06 14:40:46 +00:00
|
|
|
* Abstraction of an IP/UDP-Packet, contains data, sender and receiver.
|
2005-11-04 16:27:45 +00:00
|
|
|
*/
|
2005-11-24 09:17:51 +00:00
|
|
|
struct packet_t {
|
2005-11-16 16:07:55 +00:00
|
|
|
|
2005-11-07 09:11:58 +00:00
|
|
|
/**
|
2008-03-13 14:14:44 +00:00
|
|
|
* Set the source address.
|
2009-09-04 11:46:09 +00:00
|
|
|
*
|
2012-07-06 14:40:46 +00:00
|
|
|
* @param source address to set as source (gets owned)
|
2005-11-07 09:11:58 +00:00
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
void (*set_source)(packet_t *packet, host_t *source);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-04 16:27:45 +00:00
|
|
|
/**
|
2008-03-13 14:14:44 +00:00
|
|
|
* Set the destination address.
|
2009-09-04 11:46:09 +00:00
|
|
|
*
|
2012-07-06 14:40:46 +00:00
|
|
|
* @param source address to set as destination (gets owned)
|
2005-11-04 16:27:45 +00:00
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
void (*set_destination)(packet_t *packet, host_t *destination);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-10 15:38:12 +00:00
|
|
|
/**
|
2008-03-13 14:14:44 +00:00
|
|
|
* Get the source address.
|
2009-09-04 11:46:09 +00:00
|
|
|
*
|
2012-07-06 14:40:46 +00:00
|
|
|
* @return source address (internal data)
|
2005-12-06 16:00:07 +00:00
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
host_t *(*get_source)(packet_t *packet);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-12-06 16:00:07 +00:00
|
|
|
/**
|
2008-03-13 14:14:44 +00:00
|
|
|
* Get the destination address.
|
2009-09-04 11:46:09 +00:00
|
|
|
*
|
2012-07-06 14:40:46 +00:00
|
|
|
* @return destination address (internal data)
|
2005-12-06 16:00:07 +00:00
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
host_t *(*get_destination)(packet_t *packet);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-12-06 16:00:07 +00:00
|
|
|
/**
|
2008-03-13 14:14:44 +00:00
|
|
|
* Get the data from the packet.
|
2009-09-04 11:46:09 +00:00
|
|
|
*
|
2012-07-06 14:40:46 +00:00
|
|
|
* @return chunk containing the data (internal data)
|
2005-12-06 16:00:07 +00:00
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
chunk_t (*get_data)(packet_t *packet);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-12-06 16:00:07 +00:00
|
|
|
/**
|
2008-03-13 14:14:44 +00:00
|
|
|
* Set the data in the packet.
|
2009-09-04 11:46:09 +00:00
|
|
|
*
|
2012-07-06 14:40:46 +00:00
|
|
|
* @param data chunk with data to set (gets owned)
|
2005-12-06 16:00:07 +00:00
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
void (*set_data)(packet_t *packet, chunk_t data);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2013-02-06 10:56:27 +00:00
|
|
|
/**
|
|
|
|
* Get the DiffServ Code Point set on this packet.
|
|
|
|
*
|
|
|
|
* @return DSCP value
|
|
|
|
*/
|
2016-03-22 12:22:01 +00:00
|
|
|
uint8_t (*get_dscp)(packet_t *this);
|
2013-02-06 10:56:27 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the DiffServ Code Point to use on this packet.
|
|
|
|
*
|
|
|
|
* @param value DSCP value
|
|
|
|
*/
|
2016-03-22 12:22:01 +00:00
|
|
|
void (*set_dscp)(packet_t *this, uint8_t value);
|
2013-02-06 10:56:27 +00:00
|
|
|
|
2012-02-24 10:42:32 +00:00
|
|
|
/**
|
|
|
|
* Increase the offset where the actual packet data starts.
|
|
|
|
*
|
2012-07-06 14:40:46 +00:00
|
|
|
* The total offset applies to future calls of get_data() and clone().
|
|
|
|
*
|
2012-02-24 10:42:32 +00:00
|
|
|
* @note The offset is reset to 0 when set_data() is called.
|
|
|
|
*
|
|
|
|
* @param bytes the number of additional bytes to skip
|
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
void (*skip_bytes)(packet_t *packet, size_t bytes);
|
2012-02-24 10:42:32 +00:00
|
|
|
|
2005-12-06 16:00:07 +00:00
|
|
|
/**
|
2008-03-13 14:14:44 +00:00
|
|
|
* Clones a packet_t object.
|
2009-09-04 11:46:09 +00:00
|
|
|
*
|
2012-07-06 14:40:46 +00:00
|
|
|
* @note Data is cloned without skipped bytes.
|
|
|
|
*
|
2008-03-13 14:14:44 +00:00
|
|
|
* @param clone clone of the packet
|
2005-11-10 15:38:12 +00:00
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
packet_t* (*clone)(packet_t *packet);
|
2009-09-04 11:46:09 +00:00
|
|
|
|
2005-11-04 16:27:45 +00:00
|
|
|
/**
|
2008-03-13 14:14:44 +00:00
|
|
|
* Destroy the packet, freeing contained data.
|
2005-11-04 16:27:45 +00:00
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
void (*destroy)(packet_t *packet);
|
2005-11-04 16:27:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2012-07-06 14:40:46 +00:00
|
|
|
* Create an empty packet
|
2009-09-04 11:46:09 +00:00
|
|
|
*
|
2005-12-06 16:00:07 +00:00
|
|
|
* @return packet_t object
|
2005-11-04 16:27:45 +00:00
|
|
|
*/
|
2012-07-06 14:40:46 +00:00
|
|
|
packet_t *packet_create();
|
2005-11-04 16:27:45 +00:00
|
|
|
|
2012-07-07 10:46:28 +00:00
|
|
|
/**
|
|
|
|
* Create a packet from the supplied data
|
|
|
|
*
|
|
|
|
* @param src source address (gets owned)
|
|
|
|
* @param dst destination address (gets owned)
|
|
|
|
* @param data packet data (gets owned)
|
|
|
|
* @return packet_t object
|
|
|
|
*/
|
|
|
|
packet_t *packet_create_from_data(host_t *src, host_t *dst, chunk_t data);
|
|
|
|
|
2009-03-24 17:43:01 +00:00
|
|
|
#endif /** PACKET_H_ @}*/
|