/* When the OpenVPN protocol is ran in AEAD mode, use * the OpenVPN packet ID as the AEAD nonce: * * 00000005 521c3b01 4308c041 * [seq # ] [ nonce_tail ] * [ 12-byte full IV ] -> OVPN_NONCE_SIZE * [4-bytes -> OVPN_NONCE_WIRE_SIZE * on wire]
*/
/* nonce size (96bits) as required by AEAD ciphers */ #define OVPN_NONCE_SIZE 12 /* last 8 bytes of AEAD nonce: provided by userspace and usually derived * from key material generated during TLS handshake
*/ #define OVPN_NONCE_TAIL_SIZE 8
/* OpenVPN nonce size reduced by 8-byte nonce tail -- this is the * size of the AEAD Associated Data (AD) sent over the wire * and is normally the head of the IV
*/ #define OVPN_NONCE_WIRE_SIZE (OVPN_NONCE_SIZE - OVPN_NONCE_TAIL_SIZE)
/* packet opcodes of interest to us */ #define OVPN_DATA_V1 6 /* data channel v1 packet */ #define OVPN_DATA_V2 9 /* data channel v2 packet */
#define OVPN_PEER_ID_UNDEF 0x00FFFFFF
/** * ovpn_opcode_from_skb - extract OP code from skb at specified offset * @skb: the packet to extract the OP code from * @offset: the offset in the data buffer where the OP code is located * * Note: this function assumes that the skb head was pulled enough * to access the first 4 bytes. * * Return: the OP code
*/ staticinline u8 ovpn_opcode_from_skb(conststruct sk_buff *skb, u16 offset)
{
u32 opcode = be32_to_cpu(*(__be32 *)(skb->data + offset));
/** * ovpn_peer_id_from_skb - extract peer ID from skb at specified offset * @skb: the packet to extract the OP code from * @offset: the offset in the data buffer where the OP code is located * * Note: this function assumes that the skb head was pulled enough * to access the first 4 bytes. * * Return: the peer ID
*/ staticinline u32 ovpn_peer_id_from_skb(conststruct sk_buff *skb, u16 offset)
{
u32 opcode = be32_to_cpu(*(__be32 *)(skb->data + offset));
/** * ovpn_key_id_from_skb - extract key ID from the skb head * @skb: the packet to extract the key ID code from * * Note: this function assumes that the skb head was pulled enough * to access the first 4 bytes. * * Return: the key ID
*/ staticinline u8 ovpn_key_id_from_skb(conststruct sk_buff *skb)
{
u32 opcode = be32_to_cpu(*(__be32 *)skb->data);
/** * ovpn_opcode_compose - combine OP code, key ID and peer ID to wire format * @opcode: the OP code * @key_id: the key ID * @peer_id: the peer ID * * Return: a 4 bytes integer obtained combining all input values following the * OpenVPN wire format. This integer can then be written to the packet header.
*/ staticinline u32 ovpn_opcode_compose(u8 opcode, u8 key_id, u32 peer_id)
{ return FIELD_PREP(OVPN_OPCODE_PKTTYPE_MASK, opcode) |
FIELD_PREP(OVPN_OPCODE_KEYID_MASK, key_id) |
FIELD_PREP(OVPN_OPCODE_PEERID_MASK, peer_id);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.