From 683e3e1bbbdfe2f08dc12f1e840e71ed6088a0e3 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Thu, 24 Jan 2013 08:32:23 +0100 Subject: Rename rs_packet_flags members. Uppercase to make them appear as the constants they are, as opposed to variables. Remove 'flag' suffix, typically used for variables. Spell out HEADER. --- lib/tcp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/tcp.c') diff --git a/lib/tcp.c b/lib/tcp.c index 588d046..e2e9feb 100644 --- a/lib/tcp.c +++ b/lib/tcp.c @@ -34,7 +34,7 @@ _read_header (struct rs_packet *pkt) n = bufferevent_read (pkt->conn->bev, pkt->hdr, RS_HEADER_LEN); if (n == RS_HEADER_LEN) { - pkt->flags |= rs_packet_hdr_read_flag; + pkt->flags |= RS_PACKET_HEADER_READ; pkt->rpkt->length = (pkt->hdr[2] << 8) + pkt->hdr[3]; if (pkt->rpkt->length < 20 || pkt->rpkt->length > RS_MAX_PACKET_LEN) { @@ -89,7 +89,7 @@ _read_packet (struct rs_packet *pkt) { bufferevent_disable (pkt->conn->bev, EV_READ); rs_debug (("%s: complete packet read\n", __func__)); - pkt->flags &= ~rs_packet_hdr_read_flag; + pkt->flags &= ~RS_PACKET_HEADER_READ; memset (pkt->hdr, 0, sizeof(*pkt->hdr)); /* Checks done by rad_packet_ok: @@ -155,7 +155,7 @@ tcp_read_cb (struct bufferevent *bev, void *user_data) Room for improvement: Peek inside buffer (evbuffer_copyout()) to avoid the extra copying. */ - if ((pkt->flags & rs_packet_hdr_read_flag) == 0) + if ((pkt->flags & RS_PACKET_HEADER_READ) == 0) if (_read_header (pkt)) return; /* Error. */ _read_packet (pkt); -- cgit v1.1 From f0df8b47b0c7639ab3842c2b92c80f70b8ed66d3 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Thu, 9 May 2013 09:49:37 +0200 Subject: Update copyright years. --- lib/tcp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/tcp.c') diff --git a/lib/tcp.c b/lib/tcp.c index e2e9feb..8ea6a5e 100644 --- a/lib/tcp.c +++ b/lib/tcp.c @@ -1,5 +1,5 @@ -/* Copyright 2011 NORDUnet A/S. All rights reserved. - See LICENSE for licensing information. */ +/* Copyright 2011-2013 NORDUnet A/S. All rights reserved. + See LICENSE for licensing information. */ #if defined HAVE_CONFIG_H #include -- cgit v1.1 From 65b62d83ee72012d1171f1813b8f989f8805497c Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Wed, 15 May 2013 11:57:09 +0200 Subject: Don't crash on reading invalid messages. Also, invoke disconnected callback and close connection in error cases. --- lib/tcp.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'lib/tcp.c') diff --git a/lib/tcp.c b/lib/tcp.c index 8ea6a5e..e2b1a2f 100644 --- a/lib/tcp.c +++ b/lib/tcp.c @@ -38,7 +38,9 @@ _read_header (struct rs_packet *pkt) pkt->rpkt->length = (pkt->hdr[2] << 8) + pkt->hdr[3]; if (pkt->rpkt->length < 20 || pkt->rpkt->length > RS_MAX_PACKET_LEN) { - conn_close (&pkt->conn); + rs_debug (("%s: invalid packet length: %d\n", + __func__, pkt->rpkt->length)); + rs_conn_disconnect (pkt->conn); return rs_err_conn_push (pkt->conn, RSE_INVALID_PKT, "invalid packet length: %d", pkt->rpkt->length); @@ -55,7 +57,8 @@ _read_header (struct rs_packet *pkt) } else /* Error: libevent gave us less than the low watermark. */ { - conn_close (&pkt->conn); + rs_debug (("%s: got: %d octets reading header\n", __func__, n)); + rs_conn_disconnect (pkg->conn); return rs_err_conn_push_fl (pkt->conn, RSE_INTERNAL, __FILE__, __LINE__, "got %d octets reading header", n); } @@ -100,8 +103,9 @@ _read_packet (struct rs_packet *pkt) err = nr_packet_ok (pkt->rpkt); if (err != RSE_OK) { - conn_close (&pkt->conn); - return rs_err_conn_push_fl (pkt->conn, err, __FILE__, __LINE__, + rs_debug (("%s: %d: invalid packet\n", __func__, -err)); + rs_conn_disconnect (pkt->conn); + return rs_err_conn_push_fl (pkt->conn, -err, __FILE__, __LINE__, "invalid packet"); } -- cgit v1.1