Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: net/tools/quic/quic_packet_reader.cc

Issue 1543703002: Drop packets which are larger than kMaxPacketSize, instead of closing the connection with QUIC_PACK… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@110286048
Patch Set: Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/tools/quic/quic_packet_reader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/tools/quic/quic_packet_reader.h" 5 #include "net/tools/quic/quic_packet_reader.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #ifndef __APPLE__ 8 #ifndef __APPLE__
9 // This is a GNU header that is not present in /usr/include on MacOS 9 // This is a GNU header that is not present in /usr/include on MacOS
10 #include <features.h> 10 #include <features.h>
(...skipping 22 matching lines...) Expand all
33 } 33 }
34 34
35 void QuicPacketReader::Initialize() { 35 void QuicPacketReader::Initialize() {
36 // Zero initialize uninitialized memory. 36 // Zero initialize uninitialized memory.
37 memset(cbuf_, 0, arraysize(cbuf_)); 37 memset(cbuf_, 0, arraysize(cbuf_));
38 memset(buf_, 0, arraysize(buf_)); 38 memset(buf_, 0, arraysize(buf_));
39 memset(raw_address_, 0, sizeof(raw_address_)); 39 memset(raw_address_, 0, sizeof(raw_address_));
40 memset(mmsg_hdr_, 0, sizeof(mmsg_hdr_)); 40 memset(mmsg_hdr_, 0, sizeof(mmsg_hdr_));
41 41
42 for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) { 42 for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) {
43 iov_[i].iov_base = buf_ + (2 * kMaxPacketSize * i); 43 iov_[i].iov_base = buf_ + (kMaxPacketSize * i);
44 iov_[i].iov_len = 2 * kMaxPacketSize; 44 iov_[i].iov_len = kMaxPacketSize;
45 45
46 msghdr* hdr = &mmsg_hdr_[i].msg_hdr; 46 msghdr* hdr = &mmsg_hdr_[i].msg_hdr;
47 hdr->msg_name = &raw_address_[i]; 47 hdr->msg_name = &raw_address_[i];
48 hdr->msg_namelen = sizeof(sockaddr_storage); 48 hdr->msg_namelen = sizeof(sockaddr_storage);
49 hdr->msg_iov = &iov_[i]; 49 hdr->msg_iov = &iov_[i];
50 hdr->msg_iovlen = 1; 50 hdr->msg_iovlen = 1;
51 51
52 hdr->msg_control = cbuf_ + kSpaceForOverflowAndIp * i; 52 hdr->msg_control = cbuf_ + kSpaceForOverflowAndIp * i;
53 hdr->msg_controllen = kSpaceForOverflowAndIp; 53 hdr->msg_controllen = kSpaceForOverflowAndIp;
54 } 54 }
55 } 55 }
56 56
57 QuicPacketReader::~QuicPacketReader() { 57 QuicPacketReader::~QuicPacketReader() {
58 } 58 }
59 59
60 bool QuicPacketReader::ReadAndDispatchPackets( 60 bool QuicPacketReader::ReadAndDispatchPackets(
61 int fd, 61 int fd,
62 int port, 62 int port,
63 ProcessPacketInterface* processor, 63 ProcessPacketInterface* processor,
64 QuicPacketCount* packets_dropped) { 64 QuicPacketCount* packets_dropped) {
65 #if MMSG_MORE 65 #if MMSG_MORE
66 // Re-set the length fields in case recvmmsg has changed them. 66 // Re-set the length fields in case recvmmsg has changed them.
67 for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) { 67 for (int i = 0; i < kNumPacketsPerReadMmsgCall; ++i) {
68 iov_[i].iov_len = 2 * kMaxPacketSize; 68 iov_[i].iov_len = kMaxPacketSize;
69 mmsg_hdr_[i].msg_len = 0; 69 mmsg_hdr_[i].msg_len = 0;
70 msghdr* hdr = &mmsg_hdr_[i].msg_hdr; 70 msghdr* hdr = &mmsg_hdr_[i].msg_hdr;
71 hdr->msg_namelen = sizeof(sockaddr_storage); 71 hdr->msg_namelen = sizeof(sockaddr_storage);
72 hdr->msg_iovlen = 1; 72 hdr->msg_iovlen = 1;
73 hdr->msg_controllen = kSpaceForOverflowAndIp; 73 hdr->msg_controllen = kSpaceForOverflowAndIp;
74 } 74 }
75 75
76 int packets_read = 76 int packets_read =
77 recvmmsg(fd, mmsg_hdr_, kNumPacketsPerReadMmsgCall, 0, nullptr); 77 recvmmsg(fd, mmsg_hdr_, kNumPacketsPerReadMmsgCall, 0, nullptr);
78 78
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 return false; 111 return false;
112 #endif 112 #endif
113 } 113 }
114 114
115 /* static */ 115 /* static */
116 bool QuicPacketReader::ReadAndDispatchSinglePacket( 116 bool QuicPacketReader::ReadAndDispatchSinglePacket(
117 int fd, 117 int fd,
118 int port, 118 int port,
119 ProcessPacketInterface* processor, 119 ProcessPacketInterface* processor,
120 QuicPacketCount* packets_dropped) { 120 QuicPacketCount* packets_dropped) {
121 // Allocate some extra space so we can send an error if the packet is larger 121 char buf[kMaxPacketSize];
122 // than kMaxPacketSize.
123 char buf[2 * kMaxPacketSize];
124 122
125 IPEndPoint client_address; 123 IPEndPoint client_address;
126 IPAddressNumber server_ip; 124 IPAddressNumber server_ip;
127 int bytes_read = QuicSocketUtils::ReadPacket( 125 int bytes_read = QuicSocketUtils::ReadPacket(
128 fd, buf, arraysize(buf), packets_dropped, &server_ip, &client_address); 126 fd, buf, arraysize(buf), packets_dropped, &server_ip, &client_address);
129 127
130 if (bytes_read < 0) { 128 if (bytes_read < 0) {
131 return false; // ReadPacket failed. 129 return false; // ReadPacket failed.
132 } 130 }
133 131
134 QuicEncryptedPacket packet(buf, bytes_read, false); 132 QuicEncryptedPacket packet(buf, bytes_read, false);
135 IPEndPoint server_address(server_ip, port); 133 IPEndPoint server_address(server_ip, port);
136 processor->ProcessPacket(server_address, client_address, packet); 134 processor->ProcessPacket(server_address, client_address, packet);
137 135
138 // The socket read was successful, so return true even if packet dispatch 136 // The socket read was successful, so return true even if packet dispatch
139 // failed. 137 // failed.
140 return true; 138 return true;
141 } 139 }
142 140
143 } // namespace tools 141 } // namespace tools
144 142
145 } // namespace net 143 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_packet_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698