mini_parse.c revision fb3e20e0
17d09751dSDmitri Tikhonov/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 25392f7a3SLiteSpeed Tech/* 35392f7a3SLiteSpeed Tech * Convert from our hexdump format to binary: 45392f7a3SLiteSpeed Tech * 55392f7a3SLiteSpeed Tech * perl -p -ne 's/^[[:xdigit:]]+\s+//;s~ \|.*~~;s/\s+//g;s/([[:xdigit:]]{2})/chr hex$1/ge' 65392f7a3SLiteSpeed Tech */ 75392f7a3SLiteSpeed Tech 85392f7a3SLiteSpeed Tech#include <assert.h> 95392f7a3SLiteSpeed Tech#include <stdio.h> 105392f7a3SLiteSpeed Tech#include <stdint.h> 115392f7a3SLiteSpeed Tech#include <stdlib.h> 125392f7a3SLiteSpeed Tech#include <string.h> 13fb3e20e0SDmitri Tikhonov#ifndef WIN32 14fb3e20e0SDmitri Tikhonov#include <fcntl.h> 155392f7a3SLiteSpeed Tech#include <unistd.h> 16fb3e20e0SDmitri Tikhonov#else 17fb3e20e0SDmitri Tikhonov#include "getopt.h" 18fb3e20e0SDmitri Tikhonov#endif 195392f7a3SLiteSpeed Tech 205392f7a3SLiteSpeed Tech#include <sys/queue.h> 215392f7a3SLiteSpeed Tech#include <sys/types.h> 225392f7a3SLiteSpeed Tech#include <sys/stat.h> 235392f7a3SLiteSpeed Tech 245392f7a3SLiteSpeed Tech#include "lsquic.h" 255392f7a3SLiteSpeed Tech#include "lsquic_types.h" 265392f7a3SLiteSpeed Tech#include "lsquic_int_types.h" 275392f7a3SLiteSpeed Tech#include "lsquic_packet_common.h" 285392f7a3SLiteSpeed Tech#include "lsquic_packet_gquic.h" 295392f7a3SLiteSpeed Tech#include "lsquic_packet_in.h" 305392f7a3SLiteSpeed Tech#include "lsquic_packet_out.h" 315392f7a3SLiteSpeed Tech#include "lsquic_mm.h" 325392f7a3SLiteSpeed Tech#include "lsquic_hash.h" 335392f7a3SLiteSpeed Tech#include "lsquic_conn.h" 345392f7a3SLiteSpeed Tech#include "lsquic_rtt.h" 355392f7a3SLiteSpeed Tech#include "lsquic_mini_conn.h" 365392f7a3SLiteSpeed Tech#include "lsquic_engine_public.h" 375392f7a3SLiteSpeed Tech#include "lsquic_util.h" 385392f7a3SLiteSpeed Tech#include "lsquic_logger.h" 395392f7a3SLiteSpeed Tech#include "lsquic_str.h" 405392f7a3SLiteSpeed Tech 415392f7a3SLiteSpeed Tech 425392f7a3SLiteSpeed Techint 435392f7a3SLiteSpeed Techlsquic_enc_session_decrypt (void *enc_session_p, enum lsquic_version version, 445392f7a3SLiteSpeed Tech uint8_t path_id, uint64_t pack_num, 455392f7a3SLiteSpeed Tech unsigned char *buf, size_t *header_len, size_t data_len, 465392f7a3SLiteSpeed Tech unsigned char *diversification_nonce, 475392f7a3SLiteSpeed Tech unsigned char *buf_out, size_t max_out_len, size_t *out_len) 485392f7a3SLiteSpeed Tech{ 495392f7a3SLiteSpeed Tech memcpy(buf_out, buf, *header_len + data_len); 505392f7a3SLiteSpeed Tech *out_len = data_len; 515392f7a3SLiteSpeed Tech return 0; 525392f7a3SLiteSpeed Tech} 535392f7a3SLiteSpeed Tech 545392f7a3SLiteSpeed Tech 555392f7a3SLiteSpeed Techint 565392f7a3SLiteSpeed Techmain (int argc, char **argv) 575392f7a3SLiteSpeed Tech{ 585392f7a3SLiteSpeed Tech int opt; 595392f7a3SLiteSpeed Tech int fd = STDIN_FILENO; 605392f7a3SLiteSpeed Tech struct lsquic_engine_public enpub; 615392f7a3SLiteSpeed Tech struct lsquic_conn *lconn; 625392f7a3SLiteSpeed Tech lsquic_packet_in_t packet_in; 635392f7a3SLiteSpeed Tech unsigned char buf[0x1000]; 645392f7a3SLiteSpeed Tech ssize_t packet_sz; 65fb96f4ddSDmitri Tikhonov enum lsquic_version ver = LSQVER_043; 665392f7a3SLiteSpeed Tech 675392f7a3SLiteSpeed Tech memset(&enpub, 0, sizeof(enpub)); 685392f7a3SLiteSpeed Tech lsquic_mm_init(&enpub.enp_mm); 695392f7a3SLiteSpeed Tech 705392f7a3SLiteSpeed Tech lsquic_log_to_fstream(stderr, 0); 715392f7a3SLiteSpeed Tech lsq_log_levels[LSQLM_MINI_CONN] = LSQ_LOG_DEBUG; 725392f7a3SLiteSpeed Tech lsq_log_levels[LSQLM_NOMODULE] = LSQ_LOG_DEBUG; 735392f7a3SLiteSpeed Tech 745392f7a3SLiteSpeed Tech while (-1 != (opt = getopt(argc, argv, "v:f:h"))) 755392f7a3SLiteSpeed Tech { 765392f7a3SLiteSpeed Tech switch (opt) 775392f7a3SLiteSpeed Tech { 785392f7a3SLiteSpeed Tech case 'v': 795392f7a3SLiteSpeed Tech ver = atoi(optarg); 805392f7a3SLiteSpeed Tech break; 815392f7a3SLiteSpeed Tech case 'f': 825392f7a3SLiteSpeed Tech fd = open(optarg, O_RDONLY); 835392f7a3SLiteSpeed Tech if (fd < 0) 845392f7a3SLiteSpeed Tech { 855392f7a3SLiteSpeed Tech perror("open"); 865392f7a3SLiteSpeed Tech exit(EXIT_FAILURE); 875392f7a3SLiteSpeed Tech } 885392f7a3SLiteSpeed Tech break; 895392f7a3SLiteSpeed Tech case 'h': 905392f7a3SLiteSpeed Tech fprintf(stderr, "usage: %s [-v version] [-f input-file]\n", argv[0]); 915392f7a3SLiteSpeed Tech exit(EXIT_SUCCESS); 925392f7a3SLiteSpeed Tech default: 935392f7a3SLiteSpeed Tech exit(EXIT_FAILURE); 945392f7a3SLiteSpeed Tech } 955392f7a3SLiteSpeed Tech } 965392f7a3SLiteSpeed Tech 975392f7a3SLiteSpeed Tech packet_sz = read(fd, buf, sizeof(buf)); 985392f7a3SLiteSpeed Tech if (packet_sz < 0) 995392f7a3SLiteSpeed Tech { 1005392f7a3SLiteSpeed Tech perror("read"); 1015392f7a3SLiteSpeed Tech exit(EXIT_FAILURE); 1025392f7a3SLiteSpeed Tech } 1035392f7a3SLiteSpeed Tech 1045392f7a3SLiteSpeed Tech memset(&packet_in, 0, sizeof(packet_in)); 1055392f7a3SLiteSpeed Tech packet_in.pi_packno = 1; 1065392f7a3SLiteSpeed Tech packet_in.pi_header_sz = 0; 1075392f7a3SLiteSpeed Tech packet_in.pi_data_sz = packet_sz; 1085392f7a3SLiteSpeed Tech packet_in.pi_data = buf; 1095392f7a3SLiteSpeed Tech packet_in.pi_refcnt = 1; 1105392f7a3SLiteSpeed Tech 111a5fa05f9SDmitri Tikhonov lconn = lsquic_mini_conn_new(&enpub, &packet_in, ver); 1125392f7a3SLiteSpeed Tech lconn->cn_if->ci_packet_in(lconn, &packet_in); 1135392f7a3SLiteSpeed Tech 1145392f7a3SLiteSpeed Tech exit(EXIT_SUCCESS); 1155392f7a3SLiteSpeed Tech} 116