⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 packet.c

📁 This a good VPN source
💻 C
📖 第 1 页 / 共 4 页
字号:
/* parsing packets: formats and tools * Copyright (C) 1997 Angelos D. Keromytis. * Copyright (C) 1998-2001  D. Hugh Redelmeier. * * 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. * * RCSID $Id: packet.c,v 1.47 2004/10/16 22:46:59 mcr Exp $ */#include <stdio.h>#include <stdlib.h>#include <stddef.h>#include <netinet/in.h>#include <string.h>#include <openswan.h>#include "constants.h"#include "oswlog.h"#include "packet.h"/* ISAKMP Header: for all messages * layout from RFC 2408 "ISAKMP" section 3.1 *                      1                   2                   3 *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                          Initiator                            ! * !                            Cookie                             ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                          Responder                            ! * !                            Cookie                             ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !  Next Payload ! MjVer ! MnVer ! Exchange Type !     Flags     ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                          Message ID                           ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                            Length                             ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isa_fields[] = {    { ft_raw, COOKIE_SIZE, "initiator cookie", NULL },    { ft_raw, COOKIE_SIZE, "responder cookie", NULL },    { ft_enum, 8/BITS_PER_BYTE, "next payload type", &payload_names },    { ft_enum, 8/BITS_PER_BYTE, "ISAKMP version", &version_names },    { ft_enum, 8/BITS_PER_BYTE, "exchange type", &exchange_names },    { ft_set, 8/BITS_PER_BYTE, "flags", flag_bit_names },    { ft_raw, 32/BITS_PER_BYTE, "message ID", NULL },    { ft_len, 32/BITS_PER_BYTE, "length", NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_hdr_desc = { "ISAKMP Message", isa_fields, sizeof(struct isakmp_hdr) };/* Generic portion of all ISAKMP payloads. * layout from RFC 2408 "ISAKMP" section 3.2 * This describes the first 32-bit chunk of all payloads. * The previous next payload depends on the actual payload type. *                      1                   2                   3 *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ! Next Payload  !   RESERVED    !         Payload Length        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isag_fields[] = {    { ft_enum, 8/BITS_PER_BYTE, "next payload type", &payload_names },    { ft_mbz, 8/BITS_PER_BYTE, NULL, NULL },    { ft_len, 16/BITS_PER_BYTE, "length", NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_generic_desc = { "ISAKMP Generic Payload", isag_fields, sizeof(struct isakmp_generic) };/* ISAKMP Data Attribute (generic representation within payloads) * layout from RFC 2408 "ISAKMP" section 3.3 * This is not a payload type. * In TLV format, this is followed by a value field. *                      1                   2                   3 *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !A!       Attribute Type        !    AF=0  Attribute Length     ! * !F!                             !    AF=1  Attribute Value      ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * .                   AF=0  Attribute Value                       . * .                   AF=1  Not Transmitted                       . * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ *//* Oakley Attributes */static field_desc isaat_fields_oakley[] = {    { ft_af_enum, 16/BITS_PER_BYTE, "af+type", &oakley_attr_names },    { ft_lv, 16/BITS_PER_BYTE, "length/value", NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_oakley_attribute_desc = {    "ISAKMP Oakley attribute",    isaat_fields_oakley, sizeof(struct isakmp_attribute) };/* IPsec DOI Attributes */static field_desc isaat_fields_ipsec[] = {    { ft_af_enum, 16/BITS_PER_BYTE, "af+type", &ipsec_attr_names },    { ft_lv, 16/BITS_PER_BYTE, "length/value", NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_ipsec_attribute_desc = {    "ISAKMP IPsec DOI attribute",    isaat_fields_ipsec, sizeof(struct isakmp_attribute) };/* XAUTH Attributes */static field_desc isaat_fields_xauth[] = {    { ft_af_loose_enum, 16/BITS_PER_BYTE, "ModeCfg attr type", &modecfg_attr_names },    { ft_lv, 16/BITS_PER_BYTE, "length/value", NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_xauth_attribute_desc = {    "ISAKMP ModeCfg attribute",    isaat_fields_xauth, sizeof(struct isakmp_attribute) };/* ISAKMP Security Association Payload * layout from RFC 2408 "ISAKMP" section 3.4 * A variable length Situation follows. * Previous next payload: ISAKMP_NEXT_SA *                      1                   2                   3 *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ! Next Payload  !   RESERVED    !         Payload Length        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !              Domain of Interpretation  (DOI)                  ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                           Situation                           ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isasa_fields[] = {    { ft_enum, 8/BITS_PER_BYTE, "next payload type", &payload_names },    { ft_mbz, 8/BITS_PER_BYTE, NULL, NULL },    { ft_len, 16/BITS_PER_BYTE, "length", NULL },    { ft_enum, 32/BITS_PER_BYTE, "DOI", &doi_names },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_sa_desc = { "ISAKMP Security Association Payload", isasa_fields, sizeof(struct isakmp_sa) };static field_desc ipsec_sit_field[] = {    { ft_set, 32/BITS_PER_BYTE, "IPsec DOI SIT", &sit_bit_names },    { ft_end, 0, NULL, NULL }};struct_desc ipsec_sit_desc = { "IPsec DOI SIT", ipsec_sit_field, sizeof(u_int32_t) };/* ISAKMP Proposal Payload * layout from RFC 2408 "ISAKMP" section 3.5 * A variable length SPI follows. * Previous next payload: ISAKMP_NEXT_P *                      1                   2                   3 *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ! Next Payload  !   RESERVED    !         Payload Length        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !  Proposal #   !  Protocol-Id  !    SPI Size   !# of Transforms! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                        SPI (variable)                         ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isap_fields[] = {    { ft_enum, 8/BITS_PER_BYTE, "next payload type", &payload_names },    { ft_mbz, 8/BITS_PER_BYTE, NULL, NULL },    { ft_len, 16/BITS_PER_BYTE, "length", NULL },    { ft_nat, 8/BITS_PER_BYTE, "proposal number", NULL },    { ft_enum, 8/BITS_PER_BYTE, "protocol ID", &protocol_names },    { ft_nat, 8/BITS_PER_BYTE, "SPI size", NULL },    { ft_nat, 8/BITS_PER_BYTE, "number of transforms", NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_proposal_desc = { "ISAKMP Proposal Payload", isap_fields, sizeof(struct isakmp_proposal) };/* ISAKMP Transform Payload * layout from RFC 2408 "ISAKMP" section 3.6 * Variable length SA Attributes follow. * Previous next payload: ISAKMP_NEXT_T *                      1                   2                   3 *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ! Next Payload  !   RESERVED    !         Payload Length        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !  Transform #  !  Transform-Id !           RESERVED2           ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                        SA Attributes                          ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ *//* PROTO_ISAKMP */static field_desc isat_fields_isakmp[] = {    { ft_enum, 8/BITS_PER_BYTE, "next payload type", &payload_names },    { ft_mbz, 8/BITS_PER_BYTE, NULL, NULL },    { ft_len, 16/BITS_PER_BYTE, "length", NULL },    { ft_nat, 8/BITS_PER_BYTE, "transform number", NULL },    { ft_enum, 8/BITS_PER_BYTE, "transform ID", &isakmp_transformid_names },    { ft_mbz, 16/BITS_PER_BYTE, NULL, NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_isakmp_transform_desc = {    "ISAKMP Transform Payload (ISAKMP)",    isat_fields_isakmp, sizeof(struct isakmp_transform) };/* PROTO_IPSEC_AH */static field_desc isat_fields_ah[] = {    { ft_enum, 8/BITS_PER_BYTE, "next payload type", &payload_names },    { ft_mbz, 8/BITS_PER_BYTE, NULL, NULL },    { ft_len, 16/BITS_PER_BYTE, "length", NULL },    { ft_nat, 8/BITS_PER_BYTE, "transform number", NULL },    { ft_enum, 8/BITS_PER_BYTE, "transform ID", &ah_transformid_names },    { ft_mbz, 16/BITS_PER_BYTE, NULL, NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_ah_transform_desc = {    "ISAKMP Transform Payload (AH)",    isat_fields_ah, sizeof(struct isakmp_transform) };/* PROTO_IPSEC_ESP */static field_desc isat_fields_esp[] = {    { ft_enum, 8/BITS_PER_BYTE, "next payload type", &payload_names },    { ft_mbz, 8/BITS_PER_BYTE, NULL, NULL },    { ft_len, 16/BITS_PER_BYTE, "length", NULL },    { ft_nat, 8/BITS_PER_BYTE, "transform number", NULL },    { ft_enum, 8/BITS_PER_BYTE, "transform ID", &esp_transformid_names },    { ft_mbz, 16/BITS_PER_BYTE, NULL, NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_esp_transform_desc = {    "ISAKMP Transform Payload (ESP)",    isat_fields_esp, sizeof(struct isakmp_transform) };/* PROTO_IPCOMP */static field_desc isat_fields_ipcomp[] = {    { ft_enum, 8/BITS_PER_BYTE, "next payload type", &payload_names },    { ft_mbz, 8/BITS_PER_BYTE, NULL, NULL },    { ft_len, 16/BITS_PER_BYTE, "length", NULL },    { ft_nat, 8/BITS_PER_BYTE, "transform number", NULL },    { ft_enum, 8/BITS_PER_BYTE, "transform ID", &ipcomp_transformid_names },    { ft_mbz, 16/BITS_PER_BYTE, NULL, NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_ipcomp_transform_desc = {    "ISAKMP Transform Payload (COMP)",    isat_fields_ipcomp, sizeof(struct isakmp_transform) };/* ISAKMP Key Exchange Payload: no fixed fields beyond the generic ones. * layout from RFC 2408 "ISAKMP" section 3.7 * Variable Key Exchange Data follow the generic fields. * Previous next payload: ISAKMP_NEXT_KE *                      1                   2                   3 *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ! Next Payload  !   RESERVED    !         Payload Length        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                       Key Exchange Data                       ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */struct_desc isakmp_keyex_desc = { "ISAKMP Key Exchange Payload", isag_fields, sizeof(struct isakmp_generic) };/* ISAKMP Identification Payload * layout from RFC 2408 "ISAKMP" section 3.8 * See "struct identity" declared later. * Variable length Identification Data follow. * Previous next payload: ISAKMP_NEXT_ID *                      1                   2                   3 *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ! Next Payload  !   RESERVED    !         Payload Length        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !   ID Type     !             DOI Specific ID Data              ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                   Identification Data                         ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isaid_fields[] = {    { ft_enum, 8/BITS_PER_BYTE, "next payload type", &payload_names },    { ft_mbz, 8/BITS_PER_BYTE, NULL, NULL },    { ft_len, 16/BITS_PER_BYTE, "length", NULL },    { ft_enum, 8/BITS_PER_BYTE, "ID type", &ident_names },	/* ??? depends on DOI? */    { ft_nat, 8/BITS_PER_BYTE, "DOI specific A", NULL },	/* ??? depends on DOI? */    { ft_nat, 16/BITS_PER_BYTE, "DOI specific B", NULL },	/* ??? depends on DOI? */    { ft_end, 0, NULL, NULL }};struct_desc isakmp_identification_desc = { "ISAKMP Identification Payload", isaid_fields, sizeof(struct isakmp_id) };/* IPSEC Identification Payload Content * layout from RFC 2407 "IPsec DOI" section 4.6.2 * See struct isakmp_id declared earlier. * Note: Hashing skips the ISAKMP generic payload header * Variable length Identification Data follow. *                      1                   2                   3 *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -