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

📄 packet.c

📁 This a good VPN source
💻 C
📖 第 1 页 / 共 4 页
字号:
 * !  Next Payload !   RESERVED    !        Payload Length         ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !   ID Type     !  Protocol ID  !             Port              ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ~                     Identification Data                       ~ * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isaiid_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 },    { ft_nat, 8/BITS_PER_BYTE, "Protocol ID", NULL },	/* ??? UDP/TCP or 0? */    { ft_nat, 16/BITS_PER_BYTE, "port", NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_ipsec_identification_desc = { "ISAKMP Identification Payload (IPsec DOI)", isaiid_fields, sizeof(struct isakmp_ipsec_id) };/* ISAKMP Certificate Payload: oddball fixed field beyond the generic ones. * layout from RFC 2408 "ISAKMP" section 3.9 * Variable length Certificate Data follow the generic fields. * Previous next payload: ISAKMP_NEXT_CERT. *                      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        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * ! Cert Encoding !                                               ! * +-+-+-+-+-+-+-+-+                                               ! * ~                       Certificate Data                        ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isacert_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, "cert encoding", &cert_type_names },    { ft_end, 0, NULL, NULL }};/* Note: the size field of isakmp_ipsec_certificate_desc cannot be * sizeof(struct isakmp_cert) because that will rounded up for padding. */ struct_desc isakmp_ipsec_certificate_desc = { "ISAKMP Certificate Payload", isacert_fields, ISAKMP_CERT_SIZE };/* ISAKMP Certificate Request Payload: oddball field beyond the generic ones. * layout from RFC 2408 "ISAKMP" section 3.10 * Variable length Certificate Types and Certificate Authorities follow. * Previous next payload: ISAKMP_NEXT_CR. *                      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        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !  Cert. Type   !                                               ! * +-+-+-+-+-+-+-+-+                                               ! * ~                    Certificate Authority                      ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isacr_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, "cert type", &cert_type_names },    { ft_end, 0, NULL, NULL }};/* Note: the size field of isakmp_ipsec_cert_req_desc cannot be * sizeof(struct isakmp_cr) because that will rounded up for padding. */struct_desc isakmp_ipsec_cert_req_desc = { "ISAKMP Certificate RequestPayload", isacr_fields, ISAKMP_CR_SIZE };/* ISAKMP Hash Payload: no fixed fields beyond the generic ones. * layout from RFC 2408 "ISAKMP" section 3.11 * Variable length Hash Data follow. * Previous next payload: ISAKMP_NEXT_HASH. *                      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        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                           Hash Data                           ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */struct_desc isakmp_hash_desc = { "ISAKMP Hash Payload", isag_fields, sizeof(struct isakmp_generic) };/* ISAKMP Signature Payload: no fixed fields beyond the generic ones. * layout from RFC 2408 "ISAKMP" section 3.12 * Variable length Signature Data follow. * Previous next payload: ISAKMP_NEXT_SIG. *                      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        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                         Signature Data                        ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */struct_desc isakmp_signature_desc = { "ISAKMP Signature Payload", isag_fields, sizeof(struct isakmp_generic) };/* ISAKMP Nonce Payload: no fixed fields beyond the generic ones. * layout from RFC 2408 "ISAKMP" section 3.13 * Variable length Nonce Data follow. * Previous next payload: ISAKMP_NEXT_NONCE. *                      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        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                            Nonce Data                         ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */struct_desc isakmp_nonce_desc = { "ISAKMP Nonce Payload", isag_fields, sizeof(struct isakmp_generic) };/* ISAKMP Notification Payload * layout from RFC 2408 "ISAKMP" section 3.14 * This is followed by a variable length SPI * and then possibly by variable length Notification Data. * Previous next payload: ISAKMP_NEXT_N *                      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)                  ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !  Protocol-ID  !   SPI Size    !      Notify Message Type      ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                Security Parameter Index (SPI)                 ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                       Notification Data                       ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isan_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_nat, 8/BITS_PER_BYTE, "protocol ID", NULL },	/* ??? really enum: ISAKMP, IPSEC, ESP, ... */    { ft_nat, 8/BITS_PER_BYTE, "SPI size", NULL },    { ft_enum, 16/BITS_PER_BYTE, "Notify Message Type", &ipsec_notification_names },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_notification_desc = { "ISAKMP Notification Payload", isan_fields, sizeof(struct isakmp_notification) };/* ISAKMP Delete Payload * layout from RFC 2408 "ISAKMP" section 3.15 * This is followed by a variable length SPI. * Previous next payload: ISAKMP_NEXT_D *                      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)                  ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !  Protocol-Id  !   SPI Size    !           # of SPIs           ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~               Security Parameter Index(es) (SPI)              ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isad_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_nat, 8/BITS_PER_BYTE, "protocol ID", NULL },	/* ??? really enum: ISAKMP, IPSEC */    { ft_nat, 8/BITS_PER_BYTE, "SPI size", NULL },    { ft_nat, 16/BITS_PER_BYTE, "number of SPIs", NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_delete_desc = { "ISAKMP Delete Payload", isad_fields, sizeof(struct isakmp_delete) };/* ISAKMP Vendor ID Payload * layout from RFC 2408 "ISAKMP" section 3.15 * This is followed by a variable length VID. * Previous next payload: ISAKMP_NEXT_VID *                      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        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                                                               ! * ~                        Vendor ID (VID)                        ~ * !                                                               ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */struct_desc isakmp_vendor_id_desc = { "ISAKMP Vendor ID Payload", isag_fields, sizeof(struct isakmp_generic) };/* MODECFG *//* * From draft-dukes-ike-mode-cfg3.2. Attribute Payload                            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        !      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+      !     Type      !   RESERVED    !           Identifier          !      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+      !                                                               !      ~                           Attributes                          ~      !                                                               !      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */    static field_desc isaattr_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, "Attr Msg Type", &attr_msg_type_names },    { ft_mbz, 8/BITS_PER_BYTE, NULL, NULL },    { ft_nat, 16/BITS_PER_BYTE, "Identifier", NULL },    { ft_end, 0, NULL, NULL }};/* MODECFG *//* From draft-dukes-ike-mode-cfg3.2. Attribute Payload                           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        !     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+     !     Type      !   RESERVED    !           Identifier          !     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+     !                                                               !     !                                                               !     ~                           Attributes                          ~     !                                                               !     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+*/struct_desc isakmp_attr_desc = { "ISAKMP Mode Attribute", isaattr_fields, sizeof(struct isakmp_mode_attr) };/* ISAKMP NAT-Traversal NAT-D * layout from draft-ietf-ipsec-nat-t-ike-01.txt section 3.2 * *  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        ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !                 HASH of the address and port                  ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */struct_desc isakmp_nat_d = { "ISAKMP NAT-D Payload", isag_fields, sizeof(struct isakmp_generic) };/* ISAKMP NAT-Traversal NAT-OA * layout from draft-ietf-ipsec-nat-t-ike-01.txt section 4.2 * *  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     !   RESERVED    !            RESERVED           ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * !         IPv4 (4 octets) or IPv6 address (16 octets)           ! * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ */static field_desc isanat_oa_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 },    { ft_mbz, 24/BITS_PER_BYTE, NULL, NULL },    { ft_end, 0, NULL, NULL }};struct_desc isakmp_nat_oa = { "ISAKMP NAT-OA Payload", isanat_oa_fields, sizeof(struct isakmp_nat_oa) };/* descriptor for each payload type * * There is a slight problem in that some payloads differ, depending * on the mode.  Since this is table only used for top-level payloads, * Proposal and Transform payloads need not be handled. * That leaves only Identification payloads as a problem. * We make all these entries NULL */struct_desc *const payload_descs[ISAKMP_NEXT_ROOF] = {    NULL,				/* 0 ISAKMP_NEXT_NONE (No other payload following) */    &isakmp_sa_desc,			/* 1 ISAKMP_NEXT_SA (Security Association) */    NULL,				/* 2 ISAKMP_NEXT_P (Proposal) */    NULL,				/* 3 ISAKMP_NEXT_T (Transform) */    &isakmp_keyex_desc,			/* 4 ISAKMP_NEXT_KE (Key Exchange) */    NULL,				/* 5 ISAKMP_NEXT_ID (Identification) */    &isakmp_ipsec_certificate_desc,	/* 6 ISAKMP_NEXT_CERT (Certificate) */    &isakmp_ipsec_cert_req_desc,	/* 7 ISAKMP_NEXT_CR (Certificate Request) */    &isakmp_hash_desc,			/* 8 ISAKMP_NEXT_HASH (Hash) */    &isakmp_signature_desc,		/* 9 ISAKMP_NEXT_SIG (Signature) */    &isakmp_nonce_desc,			/* 10 ISAKMP_NEXT_NONCE (Nonce) */    &isakmp_notification_desc,		/* 11 ISAKMP_NEXT_N (Notification) */    &isakmp_delete_desc,		/* 12 ISAKMP_NEXT_D (Delete) */    &isakmp_vendor_id_desc,		/* 13 ISAKMP_NEXT_VID (Vendor ID) */    &isakmp_attr_desc,                  /* 14 ISAKMP_NEXT_ATTR (ModeCfg)  */        &isakmp_nat_d,              	/* 15=130 ISAKMP_NEXT_NATD (NAT-D) */    &isakmp_nat_oa,             	/* 16=131 ISAKMP_NEXT_NATOA (NAT-OA) */};voidinit_pbs(pb_stream *pbs, u_int8_t *start, size_t len, const char *name){    pbs->container = NULL;    pbs->desc = NULL;    pbs->name = name;    pbs->start = pbs->cur = start;    pbs->roof = start + len;    pbs->lenfld = NULL;

⌨️ 快捷键说明

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