aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-07-29 15:57:33 +0200
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-07-29 15:57:33 +0200
commit5c80e28475955ead2dd8b3adb490cd81656829f7 (patch)
treef9b6da494f3efa2a89b335942b3cff8186eeda3c /src
parent34776111048b565e38a916b5fd4b73ef1b526331 (diff)
start authentication
Diffstat (limited to 'src')
-rw-r--r--src/main.rs40
-rw-r--r--src/state.rs2
2 files changed, 36 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index e0e4335..6ddb414 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -5,8 +5,8 @@ use std::thread;
use std::time::Duration;
use ppproperly::{
- Deserialize, LcpData, LcpOpt, LcpPkt, MacAddr, PppData, PppPkt, PppoeData, PppoePkt, PppoeVal,
- Serialize,
+ AuthProto, Deserialize, LcpData, LcpOpt, LcpPkt, MacAddr, PapPkt, PppData, PppPkt, PppoeData,
+ PppoePkt, PppoeVal, Serialize,
};
use rsdsl_netlinkd::link;
use rsdsl_pppoe2::{Ppp, Pppoe, Result};
@@ -14,6 +14,9 @@ use rsdsl_pppoe2_sys::{new_discovery_socket, new_session};
use socket2::Socket;
const PPPOE_UPLINK: &str = "eth1";
+const USERNAME: &str = "foo";
+const PASSWORD: &str = "bar";
+
const MAX_ATTEMPTS: usize = 10;
const MAX_STATUS_ATTEMPTS: usize = 2;
@@ -330,7 +333,34 @@ fn session(
*ppp_state = Ppp::SyncAcked(attempt + 1);
}
- Ppp::Auth(_) => {}
+ Ppp::Auth(ref auth_proto, attempt) => {
+ if attempt >= MAX_ATTEMPTS {
+ *ppp_state = Ppp::Terminate(
+ "Maximum number of authentication attempts exceeded".into(),
+ 0,
+ );
+ continue;
+ }
+
+ match auth_proto {
+ None => {
+ *ppp_state = Ppp::Active;
+ continue;
+ }
+ Some(AuthProto::Pap) => {
+ PppPkt::new_pap(PapPkt::new_authenticate_request(
+ rand::random(),
+ USERNAME.into(),
+ PASSWORD.into(),
+ ))
+ .serialize(&mut ctl_w)?;
+ ctl_w.flush()?;
+ }
+ Some(AuthProto::Chap(_)) => {} // Packet handler takes care of this.
+ }
+
+ *ppp_state = Ppp::Auth(auth_proto.clone(), attempt + 1);
+ }
Ppp::Active => {}
Ppp::Terminate(ref reason, attempt) => {
if attempt >= MAX_ATTEMPTS {
@@ -492,7 +522,7 @@ fn handle_lcp(
*state = Ppp::SyncAck(identifier, mru, None, magic_number, attempt)
}
Ppp::SyncAck(..) => {} // Simply retransmit our previous ack.
- Ppp::SyncAcked(..) => *state = Ppp::Auth(auth_proto.clone()),
+ Ppp::SyncAcked(..) => *state = Ppp::Auth(auth_proto.clone(), 0),
_ => {
println!(
" <- unexpected lcp configure-request {}, mru: {}, authentication: {:?}",
@@ -536,7 +566,7 @@ fn handle_lcp(
*state = Ppp::SyncAcked(attempt)
}
Ppp::SyncAck(identifier, _, ref auth_proto, ..) if lcp.identifier == identifier => {
- *state = Ppp::Auth(auth_proto.clone())
+ *state = Ppp::Auth(auth_proto.clone(), 0)
}
_ => {
println!(" <- unexpected lcp configure-ack {}", lcp.identifier);
diff --git a/src/state.rs b/src/state.rs
index 4d3b2db..696a4dd 100644
--- a/src/state.rs
+++ b/src/state.rs
@@ -19,7 +19,7 @@ pub enum Ppp {
Synchronize(u8, u16, u32, usize),
SyncAck(u8, u16, Option<AuthProto>, u32, usize),
SyncAcked(usize),
- Auth(Option<AuthProto>),
+ Auth(Option<AuthProto>, usize),
Active,
Terminate(Vec<u8>, usize),
Terminate2(String),