File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libstrongswan / networking / packet.h
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Jun 3 09:46:44 2020 UTC (4 years, 3 months ago) by misho
Branches: strongswan, MAIN
CVS tags: v5_9_2p0, v5_8_4p7, HEAD
Strongswan

    1: /*
    2:  * Copyright (C) 2012 Tobias Brunner
    3:  * Copyright (C) 2005-2006 Martin Willi
    4:  * Copyright (C) 2005 Jan Hutter
    5:  * HSR Hochschule fuer Technik Rapperswil
    6:  *
    7:  * This program is free software; you can redistribute it and/or modify it
    8:  * under the terms of the GNU General Public License as published by the
    9:  * Free Software Foundation; either version 2 of the License, or (at your
   10:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
   11:  *
   12:  * This program is distributed in the hope that it will be useful, but
   13:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   14:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15:  * for more details.
   16:  */
   17: 
   18: /**
   19:  * @defgroup packet packet
   20:  * @{ @ingroup networking
   21:  */
   22: 
   23: #ifndef PACKET_H_
   24: #define PACKET_H_
   25: 
   26: typedef struct packet_t packet_t;
   27: 
   28: #include <library.h>
   29: #include <networking/host.h>
   30: 
   31: /**
   32:  * Maximum packet size we handle by default
   33:  */
   34: #define PACKET_MAX_DEFAULT 10000
   35: 
   36: /**
   37:  * Abstraction of an IP/UDP-Packet, contains data, sender and receiver.
   38:  */
   39: struct packet_t {
   40: 
   41: 	/**
   42: 	 * Set the source address.
   43: 	 *
   44: 	 * @param source	address to set as source (gets owned)
   45: 	 */
   46: 	void (*set_source)(packet_t *packet, host_t *source);
   47: 
   48: 	/**
   49: 	 * Set the destination address.
   50: 	 *
   51: 	 * @param source	address to set as destination (gets owned)
   52: 	 */
   53: 	void (*set_destination)(packet_t *packet, host_t *destination);
   54: 
   55: 	/**
   56: 	 * Get the source address.
   57: 	 *
   58: 	 * @return			source address (internal data)
   59: 	 */
   60: 	host_t *(*get_source)(packet_t *packet);
   61: 
   62: 	/**
   63: 	 * Get the destination address.
   64: 	 *
   65: 	 * @return			destination address (internal data)
   66: 	 */
   67: 	host_t *(*get_destination)(packet_t *packet);
   68: 
   69: 	/**
   70: 	 * Get the data from the packet.
   71: 	 *
   72: 	 * @return			chunk containing the data (internal data)
   73: 	 */
   74: 	chunk_t (*get_data)(packet_t *packet);
   75: 
   76: 	/**
   77: 	 * Set the data in the packet.
   78: 	 *
   79: 	 * @param data		chunk with data to set (gets owned)
   80: 	 */
   81: 	void (*set_data)(packet_t *packet, chunk_t data);
   82: 
   83: 	/**
   84: 	 * Get the DiffServ Code Point set on this packet.
   85: 	 *
   86: 	 * @return			DSCP value
   87: 	 */
   88: 	uint8_t (*get_dscp)(packet_t *this);
   89: 
   90: 	/**
   91: 	 * Set the DiffServ Code Point to use on this packet.
   92: 	 *
   93: 	 * @param value		DSCP value
   94: 	 */
   95: 	void (*set_dscp)(packet_t *this, uint8_t value);
   96: 
   97: 	/**
   98: 	 * Increase the offset where the actual packet data starts.
   99: 	 *
  100: 	 * The total offset applies to future calls of get_data() and clone().
  101: 	 *
  102: 	 * @note The offset is reset to 0 when set_data() is called.
  103: 	 *
  104: 	 * @param bytes		the number of additional bytes to skip
  105: 	 */
  106: 	void (*skip_bytes)(packet_t *packet, size_t bytes);
  107: 
  108: 	/**
  109: 	 * Clones a packet_t object.
  110: 	 *
  111: 	 * @note Data is cloned without skipped bytes.
  112: 	 *
  113: 	 * @param clone		clone of the packet
  114: 	 */
  115: 	packet_t* (*clone)(packet_t *packet);
  116: 
  117: 	/**
  118: 	 * Destroy the packet, freeing contained data.
  119: 	 */
  120: 	void (*destroy)(packet_t *packet);
  121: };
  122: 
  123: /**
  124:  * Create an empty packet
  125:  *
  126:  * @return packet_t object
  127:  */
  128: packet_t *packet_create();
  129: 
  130: /**
  131:  * Create a packet from the supplied data
  132:  *
  133:  * @param src			source address (gets owned)
  134:  * @param dst			destination address (gets owned)
  135:  * @param data			packet data (gets owned)
  136:  * @return packet_t object
  137:  */
  138: packet_t *packet_create_from_data(host_t *src, host_t *dst, chunk_t data);
  139: 
  140: #endif /** PACKET_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>