lsquic_parse_common.c revision c7d81ce1
1229fce07SDmitri Tikhonov/* Copyright (c) 2017 - 2019 LiteSpeed Technologies Inc.  See LICENSE. */
29626cfc2SDmitri Tikhonov#include <string.h>
39626cfc2SDmitri Tikhonov#include <sys/queue.h>
49626cfc2SDmitri Tikhonov#include <sys/types.h>
59626cfc2SDmitri Tikhonov
69626cfc2SDmitri Tikhonov#include "lsquic_types.h"
79626cfc2SDmitri Tikhonov#include "lsquic_int_types.h"
89626cfc2SDmitri Tikhonov#include "lsquic_packet_common.h"
99626cfc2SDmitri Tikhonov#include "lsquic_packet_in.h"
109626cfc2SDmitri Tikhonov#include "lsquic_parse_common.h"
119626cfc2SDmitri Tikhonov#include "lsquic_parse.h"
129626cfc2SDmitri Tikhonov
139626cfc2SDmitri Tikhonov
149626cfc2SDmitri Tikhonovint
159626cfc2SDmitri Tikhonovlsquic_parse_packet_in_begin (lsquic_packet_in_t *packet_in, size_t length,
169626cfc2SDmitri Tikhonov                            int is_server, struct packin_parse_state *state)
179626cfc2SDmitri Tikhonov{
189626cfc2SDmitri Tikhonov    if (length > 0)
199626cfc2SDmitri Tikhonov    {
20c7d81ce1SDmitri Tikhonov        switch (packet_in->pi_data[0] & 0xC8)
219626cfc2SDmitri Tikhonov        {
229626cfc2SDmitri Tikhonov        case 0x88:
239626cfc2SDmitri Tikhonov        case 0x80:
24c7d81ce1SDmitri Tikhonov        case 0xC8:
25c7d81ce1SDmitri Tikhonov        case 0xC0:
269626cfc2SDmitri Tikhonov            return lsquic_iquic_parse_packet_in_long_begin(packet_in, length,
279626cfc2SDmitri Tikhonov                                                            is_server, state);
289626cfc2SDmitri Tikhonov        case 0x08:
299626cfc2SDmitri Tikhonov            return lsquic_gquic_parse_packet_in_begin(packet_in, length,
309626cfc2SDmitri Tikhonov                                                            is_server, state);
319626cfc2SDmitri Tikhonov        default:
329626cfc2SDmitri Tikhonov            return lsquic_iquic_parse_packet_in_short_begin(packet_in, length,
339626cfc2SDmitri Tikhonov                                                            is_server, state);
349626cfc2SDmitri Tikhonov        }
359626cfc2SDmitri Tikhonov    }
369626cfc2SDmitri Tikhonov    else
379626cfc2SDmitri Tikhonov        return -1;
389626cfc2SDmitri Tikhonov}
399626cfc2SDmitri Tikhonov
409626cfc2SDmitri Tikhonov
419626cfc2SDmitri Tikhonovint
429626cfc2SDmitri Tikhonovlsquic_iquic_parse_packet_in_begin (struct lsquic_packet_in *packet_in,
439626cfc2SDmitri Tikhonov            size_t length, int is_server, struct packin_parse_state *state)
449626cfc2SDmitri Tikhonov{
459626cfc2SDmitri Tikhonov    if (length > 0)
469626cfc2SDmitri Tikhonov    {
479626cfc2SDmitri Tikhonov        if (0 == (packet_in->pi_data[0] & 0x80))
489626cfc2SDmitri Tikhonov            return lsquic_iquic_parse_packet_in_short_begin(packet_in, length,
499626cfc2SDmitri Tikhonov                                                            is_server, state);
509626cfc2SDmitri Tikhonov        else
519626cfc2SDmitri Tikhonov            return lsquic_iquic_parse_packet_in_long_begin(packet_in, length,
529626cfc2SDmitri Tikhonov                                                            is_server, state);
539626cfc2SDmitri Tikhonov    }
549626cfc2SDmitri Tikhonov    else
559626cfc2SDmitri Tikhonov        return -1;
569626cfc2SDmitri Tikhonov}
579626cfc2SDmitri Tikhonov
589626cfc2SDmitri Tikhonov
59