aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-08-14 12:58:45 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-08-14 12:58:45 +0200
commite3fd3786f15a7692d00caf3fdd6d964f0d2d759e (patch)
treeabb2ea2acdaeecbbd7fde468917ec0d3c49254d8
parent869aaa6954e12b658a183451a99c252c0718fa61 (diff)
ignore invalid ethertypes without calling the real deserialize
-rw-r--r--Cargo.lock2
-rw-r--r--src/main.rs29
2 files changed, 23 insertions, 8 deletions
diff --git a/Cargo.lock b/Cargo.lock
index da41ad6..f46411a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -631,7 +631,7 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "ppproperly"
version = "0.1.0"
-source = "git+https://github.com/rsdsl/ppproperly.git#76b1248413787f4e710ee32527b4f2161a21f46c"
+source = "git+https://github.com/rsdsl/ppproperly.git#ab2277d70070369d57ba4854af5f1c03b19f8ae3"
dependencies = [
"bitfield",
"ppproperly_macros",
diff --git a/src/main.rs b/src/main.rs
index fc77314..7a892b3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,15 +1,15 @@
use std::collections::HashMap;
use std::fs::File;
-use std::io::{BufRead, BufReader, BufWriter, Write};
+use std::io::{BufRead, BufReader, BufWriter, Read, Write};
use std::net::{Ipv4Addr, Ipv6Addr};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant};
use ppproperly::{
- AuthProto, ChapAlgorithm, ChapData, ChapPkt, Deserialize, IpcpData, IpcpOpt, IpcpPkt,
- Ipv6cpData, Ipv6cpOpt, Ipv6cpPkt, LcpData, LcpOpt, LcpPkt, MacAddr, PapData, PapPkt, PppData,
- PppPkt, PppoeData, PppoePkt, PppoeVal, Serialize, IPCP, IPV6CP,
+ AuthProto, ChapAlgorithm, ChapData, ChapPkt, Deserialize, EtherType, IpcpData, IpcpOpt,
+ IpcpPkt, Ipv6cpData, Ipv6cpOpt, Ipv6cpPkt, LcpData, LcpOpt, LcpPkt, MacAddr, PapData, PapPkt,
+ PppData, PppPkt, PppoeData, PppoePkt, PppoeVal, Serialize, IPCP, IPV6CP,
};
use rsdsl_ip_config::{DsConfig, Ipv4Config, Ipv6Config};
use rsdsl_netlinkd::link;
@@ -153,16 +153,31 @@ fn connect(interface: &str) -> Result<()> {
fn recv_discovery(
interface: &str,
- sock: Socket,
+ mut sock: Socket,
local_mac: MacAddr,
state: Arc<Mutex<Pppoe>>,
) -> Result<()> {
let mut sock_w = BufWriter::with_capacity(1500, sock.try_clone()?);
- let mut sock_r = BufReader::with_capacity(1500, sock.try_clone()?);
loop {
+ let mut buf = [0; 1522];
+ let n = sock.read(&mut buf)?;
+ let mut buf = &buf[..n];
+
+ let mut ether_type = EtherType::default();
+ match ether_type.deserialize(&mut &buf[12..14]) {
+ Ok(_) => {}
+ Err(e) => {
+ if let ppproperly::Error::InvalidEtherType(_) = e {
+ continue;
+ } else {
+ return Err(e.into());
+ }
+ }
+ }
+
let mut pkt = PppoePkt::default();
- pkt.deserialize(&mut sock_r)?;
+ pkt.deserialize(&mut buf)?;
match *state.lock().expect("pppoe state mutex is poisoned") {
Pppoe::Request(remote_mac, ..) => {