Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quicly hotfix pcb - fix chksum verify #343

Merged
merged 7 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/cnet-quic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Edit the cndp/examples/quic.jsonc file to add your interfaces and other machine
% sudo ifconfig enp94s0f0 198.18.0.2/24 up
% sudo ethtool -N enp94s0f0 flow-type udp4 action 11 # must match the qid in the jsonc file.
%
% ./tools/rcndp cnet-quic -c examples/cnet-quic/quic.jsonc -- -c examples/cnet-quic/server.crt -k examples/cnet-quic/server.key 0.0.0.0 4433
% ./tools/rcndp cnet-quic -c examples/cnet-quic/quic.jsonc -- -c examples/cnet-quic/server.crt -k examples/cnet-quic/server.key 192.168.0.2 4433
```

``` console
Expand Down
1 change: 1 addition & 0 deletions examples/cnet-quic/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ if quicly_dep.found()
]

warning_flags = [
'-Wno-error',
'-Wno-cast-qual',
'-Wno-unused-parameter',
'-Wno-sign-compare',
Expand Down
6 changes: 3 additions & 3 deletions examples/cnet-quic/quic-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -825,8 +825,8 @@ run_server(int cd, pktmbuf_t *mbuf)
break;
} else {
/* new connection */
int ret =
quicly_accept(&conn, &ctx, NULL, &remote.sa, &packet, token, &next_cid, NULL);
int ret = quicly_accept(&conn, &ctx, NULL, &remote.sa, &packet, token, &next_cid,
NULL, NULL);
if (ret == 0) {
assert(conn != NULL);
++next_cid.master_id;
Expand Down Expand Up @@ -1493,7 +1493,7 @@ open_quic_channel(void)

ret =
quicly_connect(&conn, &ctx, cinfo->host, (struct sockaddr *)&cinfo->sa, NULL, &next_cid,
resumption_token, &hs_properties, &resumed_transport_params);
resumption_token, &hs_properties, &resumed_transport_params, NULL);
assert(ret == 0);
++next_cid.master_id;
enqueue_requests(conn);
Expand Down
52 changes: 28 additions & 24 deletions lib/cnet/tcp/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,33 @@
#include "tcp_input_priv.h"

/* The TCP/IP Pseudo header */
typedef struct tcpip_s2 {
typedef struct l3_s2 {
union {
struct cne_ipv4_hdr ip4; /* IPv4 header */
struct cne_ipv6_hdr ip6; /* IPv6 header */
struct cne_ipv4_hdr *ip4; /* IPv4 header */
struct cne_ipv6_hdr *ip6; /* IPv6 header */
};
struct cne_tcp_hdr tcp; /* TCP header */
} __cne_packed tcpip_t2;
} __cne_packed l3_t2;

static inline uint16_t
tcp_input_lookup(struct cne_node *node, pktmbuf_t *m, struct pcb_hd *hd)
{
struct cnet *cnet = this_cnet;
tcpip_t2 *tip;
struct cne_tcp_hdr *tcp; /* TCP header */
void *l3;
l3_t2 tip;
struct pcb_key key = {0};
struct pcb_entry *pcb;
struct cnet_metadata *md;
uint16_t csum;
int16_t csum;
int a_family, a_len;
struct pcb_entry *pcb2;

md = pktmbuf_metadata(m);
if (!md)
return TCP_INPUT_NEXT_PKT_DROP;

tip = pktmbuf_mtod(m, struct tcpip_s2 *);
l3 = pktmbuf_mtod(m, void *);
tcp = pktmbuf_mtod_offset(m, struct cne_tcp_hdr *, m->l3_len);

pcb2 = m->userptr;
if (pcb2 && pcb2->ch && pcb2->ch->ch_proto)
Expand All @@ -66,36 +68,38 @@ tcp_input_lookup(struct cne_node *node, pktmbuf_t *m, struct pcb_hd *hd)
if (!CNET_ENABLE_IP6 && a_family == AF_INET6)
CNE_ERR_RET(" [cyan]IPv6 is disabled[]\n");

if (a_family == AF_INET6)
a_len = sizeof(struct in6_addr);
else
a_len = sizeof(struct in_addr);
if (a_family == AF_INET6) {
a_len = sizeof(struct in6_addr);
tip.ip6 = l3;
} else {
a_len = sizeof(struct in_addr);
tip.ip4 = l3;
}

/* Convert this into AVX instructions */
in_caddr_update(&key.faddr, a_family, a_len, tip->tcp.src_port);
in_caddr_update(&key.faddr, a_family, a_len, tcp->src_port);
if (a_family == AF_INET6)
inet6_addr_copy_from_octs(&key.faddr.cin6_addr, tip->ip6.src_addr);
inet6_addr_copy_from_octs(&key.faddr.cin6_addr, tip.ip6->src_addr);
else
key.faddr.cin_addr.s_addr = tip->ip4.src_addr;
in_caddr_update(&key.laddr, a_family, a_len, tip->tcp.dst_port);
key.faddr.cin_addr.s_addr = tip.ip4->src_addr;
in_caddr_update(&key.laddr, a_family, a_len, tcp->dst_port);
if (a_family == AF_INET6)
inet6_addr_copy_from_octs(&key.laddr.cin6_addr, tip->ip6.dst_addr);
inet6_addr_copy_from_octs(&key.laddr.cin6_addr, tip.ip6->dst_addr);
else
key.laddr.cin_addr.s_addr = tip->ip4.dst_addr;
key.laddr.cin_addr.s_addr = tip.ip4->dst_addr;

md->faddr.cin_port = be16toh(tip->tcp.src_port);
md->laddr.cin_port = be16toh(tip->tcp.dst_port);
md->faddr.cin_port = key.faddr.cin_port = tcp->src_port;
md->laddr.cin_port = key.laddr.cin_port = tcp->dst_port;

/* Create a 4x PCB lookup routine */
pcb = cnet_pcb_lookup(hd, &key, BEST_MATCH);
if (likely(pcb)) {
int rc = TCP_INPUT_NEXT_PKT_DROP;

if (is_pcb_dom_inet6(pcb))
csum = cne_ipv6_udptcp_cksum_verify(&tip->ip6, &tip->tcp);
csum = cne_ipv6_udptcp_cksum_verify(l3, tcp);
else
csum = cne_ipv4_udptcp_cksum_verify(&tip->ip4, &tip->tcp);
if (csum)
csum = cne_ipv4_udptcp_cksum_verify(l3, tcp);
if (csum < 0)
return rc;

m->userptr = pcb;
Expand Down
57 changes: 32 additions & 25 deletions lib/cnet/udp/udp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,24 @@
#include "udp_input_priv.h"

/* The UDP/IP Pseudo header */
typedef struct udpip_s2 {
typedef struct l3_s2 {
union {
struct cne_ipv4_hdr ip4; /* IPv4 header */
struct cne_ipv6_hdr ip6; /* IPv6 header */
struct cne_ipv4_hdr *ip4; /* IPv4 header */
struct cne_ipv6_hdr *ip6; /* IPv6 header */
};
struct cne_udp_hdr udp; /* UDP header */
} __cne_packed udpip_t2;
} __cne_packed l3_t2;

static inline uint16_t
udp_input_lookup(pktmbuf_t *m, struct pcb_hd *hd)
{
struct cnet *cnet = this_cnet;
udpip_t2 *uip;
void *l3;
l3_t2 uip;
struct cne_udp_hdr *udp;
struct pcb_key key = {0};
struct pcb_entry *pcb;
struct cnet_metadata *md;
uint16_t csum;
int16_t csum;
int a_family, a_len;
struct pcb_entry *pcb2;

Expand All @@ -58,7 +59,8 @@ udp_input_lookup(pktmbuf_t *m, struct pcb_hd *hd)
return UDP_INPUT_NEXT_PKT_DROP;

/* Assume we point to the L3 header here */
uip = pktmbuf_mtod(m, struct udpip_s2 *);
l3 = pktmbuf_mtod(m, void *);
udp = pktmbuf_mtod_offset(m, struct cne_udp_hdr *, m->l3_len);

pcb2 = m->userptr;
if (pcb2 && pcb2->ch && pcb2->ch->ch_proto)
Expand All @@ -69,35 +71,40 @@ udp_input_lookup(pktmbuf_t *m, struct pcb_hd *hd)
if (!CNET_ENABLE_IP6 && a_family == AF_INET6)
CNE_ERR_RET(" [cyan]IPv6 is disabled[]\n");

if (a_family == AF_INET6)
a_len = sizeof(struct in6_addr);
else
a_len = sizeof(struct in_addr);
if (a_family == AF_INET6) {
a_len = sizeof(struct in6_addr);
uip.ip6 = l3;
} else {
a_len = sizeof(struct in_addr);
uip.ip4 = l3;
}

/* Convert this into AVX instructions */
in_caddr_update(&key.faddr, a_family, a_len, uip->udp.src_port);
in_caddr_update(&key.faddr, a_family, a_len, udp->src_port);
if (a_family == AF_INET6)
inet6_addr_copy_from_octs(&key.faddr.cin6_addr, uip->ip6.src_addr);
inet6_addr_copy_from_octs(&key.faddr.cin6_addr, uip.ip6->src_addr);
else
key.faddr.cin_addr.s_addr = uip->ip4.src_addr;
in_caddr_update(&key.laddr, a_family, a_len, uip->udp.dst_port);
key.faddr.cin_addr.s_addr = uip.ip4->src_addr;

in_caddr_update(&key.laddr, a_family, a_len, udp->dst_port);
if (a_family == AF_INET6)
inet6_addr_copy_from_octs(&key.laddr.cin6_addr, uip->ip6.dst_addr);
inet6_addr_copy_from_octs(&key.laddr.cin6_addr, uip.ip6->dst_addr);
else
key.laddr.cin_addr.s_addr = uip->ip4.dst_addr;
key.laddr.cin_addr.s_addr = uip.ip4->dst_addr;

md->faddr.cin_port = be16toh(uip->udp.src_port);
md->laddr.cin_port = be16toh(uip->udp.dst_port);
md->faddr.cin_port = key.faddr.cin_port = udp->src_port;
md->laddr.cin_port = key.laddr.cin_port = udp->dst_port;

/* Create a 4x PCB lookup routine */
pcb = cnet_pcb_lookup(hd, &key, BEST_MATCH);
if (likely(pcb)) {
if ((pcb->opt_flag & UDP_CHKSUM_FLAG) && uip->udp.dgram_cksum) {
if ((pcb->opt_flag & UDP_CHKSUM_FLAG) && udp->dgram_cksum) {
if (is_pcb_dom_inet6(pcb))
csum = cne_ipv6_udptcp_cksum_verify(&uip->ip6, &uip->udp);
else
csum = cne_ipv4_udptcp_cksum_verify(&uip->ip4, &uip->udp);
if (csum)
csum = cne_ipv6_udptcp_cksum_verify(l3, udp);
else {
csum = cne_ipv4_udptcp_cksum_verify(l3, udp);
}
if (csum < 0)
return UDP_INPUT_NEXT_PKT_DROP;
}
m->userptr = pcb;
Expand Down
Loading