mirror of
https://github.com/D-Modem/login.git
synced 2026-11-28 12:28:07 -08:00
PPP address pool, isolated dial-up network and DNS overrides
- [ppp_pool]: each PPP caller gets its own address of a range
({ppp_local}, {ppp_remote}, {ppp_dns}, {ppp_dns2} and MODEM_PPP_*),
as flock'd lock files in state_dir/ppp-pool shared by every modemmenu
and -serve session, so several lines can run PPP at once. The samples
move to 10.77.0.0/24 with the pool.
- dialup/: modemmenu-dialup puts the callers' links in a VRF of their
own, egress by a VLAN, the host's uplink (NAT) or none, with an
nftables firewall: only the listed service ports of the host, no
private range (host LANs, other callers) unless ALLOW_CIDRS opens it.
pppd's ip-up.d/ip-down.d hooks attach each link.
- modemmenu-dns: dnsmasq in the VRF on 10.77.0.1, with overrides from
/etc/modemmenu/dns.d/*.conf (AIM/ICQ, AOL, MSN, Yahoo names ready).
- make install-dialup, docs/dialup-network.md; confref reads section
names with underscores.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRVTwDhoXdaYHRwQ4BT
This commit is contained in:
23 files changed
+886
-23
No files matched your search
@@ -9,6 +9,9 @@
|
||||
# plugin into pppd's plugin directory
|
||||
# make install-freepbx into $(BINDIR), freepbx/'s samples into
|
||||
# /etc/modemmenu and modemmenu.service into systemd
|
||||
# make install-dialup the PPP callers' network (docs/dialup-network.md):
|
||||
# modemmenu-dialup, pppd's hooks, the units, and
|
||||
# dialup.conf, dnsmasq.conf, dns.d/ in /etc/modemmenu
|
||||
|
||||
GO ?= go
|
||||
BINDIR ?= /usr/local/bin
|
||||
@@ -65,4 +68,19 @@ clean:
|
||||
rm -f modemmenu pppd/modemmenu.so
|
||||
|
||||
FORCE:
|
||||
.PHONY: all test install install-freepbx clean FORCE
|
||||
.PHONY: all test install install-freepbx install-dialup clean FORCE
|
||||
|
||||
# the PPP callers' network: files already in /etc/modemmenu are kept
|
||||
SBINDIR ?= /usr/local/sbin
|
||||
install-dialup:
|
||||
install -D -m 755 dialup/modemmenu-dialup $(DESTDIR)$(SBINDIR)/modemmenu-dialup
|
||||
install -D -m 755 dialup/ip-up $(DESTDIR)/etc/ppp/ip-up.d/modemmenu-dialup
|
||||
install -D -m 755 dialup/ip-down $(DESTDIR)/etc/ppp/ip-down.d/modemmenu-dialup
|
||||
install -D -m 644 dialup/modemmenu-dialup.service $(DESTDIR)/etc/systemd/system/modemmenu-dialup.service
|
||||
install -D -m 644 dialup/modemmenu-dns.service $(DESTDIR)/etc/systemd/system/modemmenu-dns.service
|
||||
[ -e $(DESTDIR)$(FREEPBX_CONF_DIR)/dialup.conf ] || \
|
||||
install -D -m 644 dialup/dialup.conf.sample $(DESTDIR)$(FREEPBX_CONF_DIR)/dialup.conf
|
||||
[ -e $(DESTDIR)$(FREEPBX_CONF_DIR)/dnsmasq.conf ] || \
|
||||
install -D -m 644 dialup/dnsmasq.conf $(DESTDIR)$(FREEPBX_CONF_DIR)/dnsmasq.conf
|
||||
[ -e $(DESTDIR)$(FREEPBX_CONF_DIR)/dns.d/services.conf ] || \
|
||||
install -D -m 644 dialup/dns.d/services.conf $(DESTDIR)$(FREEPBX_CONF_DIR)/dns.d/services.conf
|
||||
@@ -227,8 +227,6 @@ func autoPPP(t *term.Term, s *settings, sess *session) int {
|
||||
|
||||
v := sess.vars(false)
|
||||
v["auth_socket"] = a.path()
|
||||
cmd := exec.Command("/bin/sh", "-c", config.Expand(s.autoppp.command, v, shellQuote))
|
||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stdout
|
||||
env := make([]string, 0, 32)
|
||||
for _, e := range os.Environ() {
|
||||
if !strings.HasPrefix(e, "MODEM_") {
|
||||
@@ -236,6 +234,20 @@ func autoPPP(t *term.Term, s *settings, sess *session) int {
|
||||
}
|
||||
}
|
||||
env = append(env, sess.environ(false)...)
|
||||
// the caller's address, from [ppp_pool]: taken before the login (pppd
|
||||
// needs it on its command line), given back when pppd ends
|
||||
lease, err := leaseFor(s, s.autoppp.command, "")
|
||||
if err != nil {
|
||||
logf("autoppp: ppp_pool: %v %v", err, sess)
|
||||
return 1
|
||||
}
|
||||
if lease != nil {
|
||||
defer lease.close()
|
||||
env = lease.add(v, env)
|
||||
logf("autoppp: %s for the caller %v", lease.remote, sess)
|
||||
}
|
||||
cmd := exec.Command("/bin/sh", "-c", config.Expand(s.autoppp.command, v, shellQuote))
|
||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stdout
|
||||
env = append(env, "MODEMMENU_AUTH_SOCKET="+a.path())
|
||||
cmd.Env = env
|
||||
before := t.SetMode("raw")
|
||||
|
||||
+12
-1
@@ -108,6 +108,17 @@ func runExec(t *term.Term, cfg *settings, it *menuItem, s *session, deadline tim
|
||||
"MODEM_DROPFILE="+df.files[0])
|
||||
}
|
||||
|
||||
// a PPP caller's address, from [ppp_pool]
|
||||
lease, err := leaseFor(cfg, it.command, s.User)
|
||||
if err != nil {
|
||||
return fmt.Errorf("ppp_pool: %v", err)
|
||||
}
|
||||
if lease != nil {
|
||||
defer lease.close()
|
||||
env = lease.add(v, env)
|
||||
logf("%s: user=%s gets %s", it.name, s.User, lease.remote)
|
||||
}
|
||||
|
||||
cmd := exec.Command("/bin/sh", "-c", config.Expand(it.command, v, shellQuote))
|
||||
cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stdout
|
||||
if cred != nil {
|
||||
@@ -141,7 +152,7 @@ func runExec(t *term.Term, cfg *settings, it *menuItem, s *session, deadline tim
|
||||
})
|
||||
defer timer.Stop()
|
||||
}
|
||||
err := cmd.Wait()
|
||||
err = cmd.Wait()
|
||||
running(nil)
|
||||
if timedOut.Load() {
|
||||
return errTimeLimit
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
// Copyright (C) 2026 D-Modem Authors
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package main
|
||||
|
||||
// The PPP address pool: each PPP caller gets an address of its own from
|
||||
// [ppp_pool] range, so that several lines can run PPP at once. A command
|
||||
// that names {ppp_remote} (or {ppp_local}, {ppp_dns}) takes an address
|
||||
// before it starts and gives it back when it ends. The addresses are lock
|
||||
// files in state_dir/ppp-pool, held while pppd runs: a modemmenu per call
|
||||
// and the sessions of modemmenu -serve share them, and an address comes
|
||||
// back by itself when its modemmenu dies.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/D-Modem/menu/internal/config"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// pppPoolSettings: [ppp_pool]
|
||||
type pppPoolSettings struct {
|
||||
enabled bool
|
||||
local netip.Addr // the server's end of every link
|
||||
first, last netip.Addr // the callers' addresses, both included
|
||||
dns []netip.Addr // offered to the callers (ms-dns), at most 2
|
||||
}
|
||||
|
||||
// pppPoolMax: a range larger than this is a typo, not a pool
|
||||
const pppPoolMax = 4096
|
||||
|
||||
// loadPPPPool: [ppp_pool], checked; no range: no pool
|
||||
func loadPPPPool(sec *config.Section) (pppPoolSettings, error) {
|
||||
var p pppPoolSettings
|
||||
r := strings.TrimSpace(sec.Get("range", ""))
|
||||
if r == "" {
|
||||
return p, nil
|
||||
}
|
||||
lo, hi, ok := strings.Cut(r, "-")
|
||||
if !ok {
|
||||
return p, fmt.Errorf("[ppp_pool] range: %q (first-last, e.g. 192.168.77.10-192.168.77.99)", r)
|
||||
}
|
||||
var err error
|
||||
if p.first, err = parseIPv4(strings.TrimSpace(lo)); err != nil {
|
||||
return p, fmt.Errorf("[ppp_pool] range: %v", err)
|
||||
}
|
||||
// the last may be the whole address or its last number alone
|
||||
hi = strings.TrimSpace(hi)
|
||||
if !strings.Contains(hi, ".") {
|
||||
b := p.first.As4()
|
||||
hi = fmt.Sprintf("%d.%d.%d.%s", b[0], b[1], b[2], hi)
|
||||
}
|
||||
if p.last, err = parseIPv4(hi); err != nil {
|
||||
return p, fmt.Errorf("[ppp_pool] range: %v", err)
|
||||
}
|
||||
if p.last.Less(p.first) {
|
||||
return p, fmt.Errorf("[ppp_pool] range: %s comes before %s", p.last, p.first)
|
||||
}
|
||||
if n := addrIndex(p.first, p.last); n >= pppPoolMax {
|
||||
return p, fmt.Errorf("[ppp_pool] range: %d addresses (at most %d)", n+1, pppPoolMax)
|
||||
}
|
||||
l := strings.TrimSpace(sec.Get("local", ""))
|
||||
if l == "" {
|
||||
return p, fmt.Errorf("[ppp_pool] local: the server's address on the links (e.g. 192.168.77.1)")
|
||||
}
|
||||
if p.local, err = parseIPv4(l); err != nil {
|
||||
return p, fmt.Errorf("[ppp_pool] local: %v", err)
|
||||
}
|
||||
if !p.local.Less(p.first) && !p.last.Less(p.local) {
|
||||
return p, fmt.Errorf("[ppp_pool] local: %s is in the range", p.local)
|
||||
}
|
||||
for _, d := range config.Fields(sec.Get("dns", l)) {
|
||||
a, err := parseIPv4(d)
|
||||
if err != nil {
|
||||
return p, fmt.Errorf("[ppp_pool] dns: %v", err)
|
||||
}
|
||||
p.dns = append(p.dns, a)
|
||||
}
|
||||
if len(p.dns) > 2 {
|
||||
return p, fmt.Errorf("[ppp_pool] dns: at most 2 servers (PPP offers a primary and a secondary)")
|
||||
}
|
||||
p.enabled = true
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func parseIPv4(s string) (netip.Addr, error) {
|
||||
a, err := netip.ParseAddr(s)
|
||||
if err != nil || !a.Is4() {
|
||||
return netip.Addr{}, fmt.Errorf("%q: not an IPv4 address", s)
|
||||
}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// addrIndex: how far b is after a
|
||||
func addrIndex(a, b netip.Addr) int {
|
||||
x, y := a.As4(), b.As4()
|
||||
ax := uint32(x[0])<<24 | uint32(x[1])<<16 | uint32(x[2])<<8 | uint32(x[3])
|
||||
bx := uint32(y[0])<<24 | uint32(y[1])<<16 | uint32(y[2])<<8 | uint32(y[3])
|
||||
return int(bx - ax)
|
||||
}
|
||||
|
||||
// usesPool: whether a command names the pool's placeholders
|
||||
func usesPool(command string) bool {
|
||||
c := strings.ToLower(command)
|
||||
for _, k := range []string{"{ppp_remote}", "{ppp_local}", "{ppp_dns}", "{ppp_dns2}"} {
|
||||
if strings.Contains(c, k) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// pppLease: an address of the pool, until close
|
||||
type pppLease struct {
|
||||
remote netip.Addr
|
||||
p *pppPoolSettings
|
||||
f *os.File
|
||||
}
|
||||
|
||||
// takeAddress: the first free address of the pool, for user (written in
|
||||
// its lock file, for whoever looks)
|
||||
func takeAddress(p *pppPoolSettings, stateDir, user string) (*pppLease, error) {
|
||||
dir := filepath.Join(stateDir, "ppp-pool")
|
||||
if err := os.MkdirAll(dir, 0o700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for a := p.first; ; a = a.Next() {
|
||||
f, err := os.OpenFile(filepath.Join(dir, a.String()), os.O_RDWR|os.O_CREATE, 0o600)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if unix.Flock(int(f.Fd()), unix.LOCK_EX|unix.LOCK_NB) == nil {
|
||||
f.Truncate(0)
|
||||
f.WriteAt([]byte(fmt.Sprintf("%s %d\n", user, os.Getpid())), 0)
|
||||
return &pppLease{remote: a, p: p, f: f}, nil
|
||||
}
|
||||
f.Close()
|
||||
if a == p.last {
|
||||
break
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("all %d PPP addresses are in use", addrIndex(p.first, p.last)+1)
|
||||
}
|
||||
|
||||
// close: the address is free again
|
||||
func (l *pppLease) close() {
|
||||
if l != nil && l.f != nil {
|
||||
l.f.Truncate(0)
|
||||
l.f.Close()
|
||||
l.f = nil
|
||||
}
|
||||
}
|
||||
|
||||
// vars: {ppp_local}, {ppp_remote}, {ppp_dns}, {ppp_dns2} (the first
|
||||
// again when there is no second, so ms-dns {ppp_dns2} always has one)
|
||||
func (l *pppLease) vars() map[string]string {
|
||||
v := map[string]string{
|
||||
"ppp_local": l.p.local.String(),
|
||||
"ppp_remote": l.remote.String(),
|
||||
}
|
||||
if len(l.p.dns) > 0 {
|
||||
v["ppp_dns"], v["ppp_dns2"] = l.p.dns[0].String(), l.p.dns[0].String()
|
||||
}
|
||||
if len(l.p.dns) > 1 {
|
||||
v["ppp_dns2"] = l.p.dns[1].String()
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// add: the lease to a command's placeholders and environment (MODEM_PPP_*)
|
||||
func (l *pppLease) add(v map[string]string, env []string) []string {
|
||||
for k, val := range l.vars() {
|
||||
v[k] = val
|
||||
env = append(env, "MODEM_"+strings.ToUpper(k)+"="+val)
|
||||
}
|
||||
return env
|
||||
}
|
||||
|
||||
// leaseFor: an address when command names the pool, else nil
|
||||
func leaseFor(cfg *settings, command, user string) (*pppLease, error) {
|
||||
if !usesPool(command) {
|
||||
return nil, nil
|
||||
}
|
||||
return takeAddress(&cfg.pppPool, cfg.limits.stateDir, user)
|
||||
}
|
||||
|
||||
// checkPool: a command that names the pool needs one
|
||||
func checkPool(s *settings) error {
|
||||
if s.pppPool.enabled {
|
||||
return nil
|
||||
}
|
||||
for _, it := range s.items {
|
||||
if it.mode == "exec" && usesPool(it.command) {
|
||||
return fmt.Errorf("[item %s] command: {ppp_...} needs [ppp_pool] range", it.name)
|
||||
}
|
||||
}
|
||||
if s.autoppp.enabled && usesPool(s.autoppp.command) {
|
||||
return fmt.Errorf("[autoppp] command: {ppp_...} needs [ppp_pool] range")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
// Copyright (C) 2026 D-Modem Authors
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/D-Modem/menu/internal/config"
|
||||
)
|
||||
|
||||
// poolConf: a configuration with [ppp_pool] pool and an item command
|
||||
func poolConf(t *testing.T, pool, command string) (*settings, error) {
|
||||
t.Helper()
|
||||
dir := t.TempDir()
|
||||
users := filepath.Join(dir, "users")
|
||||
os.WriteFile(users, nil, 0o600)
|
||||
p := filepath.Join(dir, "c.conf")
|
||||
os.WriteFile(p, []byte("[general]\nlog = none\nauth = file\nstate_dir = "+dir+"\n[file]\npath = "+users+
|
||||
"\n[ppp_pool]\n"+pool+"\n[item ppp]\nkey = P\nmode = exec\ncommand = "+command+"\n"), 0o600)
|
||||
return loadSettings(p)
|
||||
}
|
||||
|
||||
// the addresses: each taken once, given back on close, none past the last
|
||||
func TestPPPPool(t *testing.T) {
|
||||
s, err := poolConf(t, "local = 10.77.0.1\nrange = 10.77.0.10-12\ndns = 10.77.0.1 9.9.9.9",
|
||||
"pppd {ppp_local}:{ppp_remote} ms-dns {ppp_dns} ms-dns {ppp_dns2}")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var leases []*pppLease
|
||||
for _, want := range []string{"10.77.0.10", "10.77.0.11", "10.77.0.12"} {
|
||||
l, err := leaseFor(s, s.items[0].command, "alice")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if l.remote.String() != want {
|
||||
t.Errorf("got %s, want %s", l.remote, want)
|
||||
}
|
||||
leases = append(leases, l)
|
||||
}
|
||||
if _, err := leaseFor(s, s.items[0].command, "bob"); err == nil || !strings.Contains(err.Error(), "all 3") {
|
||||
t.Errorf("a full pool: %v", err)
|
||||
}
|
||||
// who has it, for whoever looks
|
||||
b, _ := os.ReadFile(filepath.Join(s.limits.stateDir, "ppp-pool", "10.77.0.11"))
|
||||
if !strings.HasPrefix(string(b), "alice ") {
|
||||
t.Errorf("lock file: %q", b)
|
||||
}
|
||||
leases[1].close()
|
||||
l, err := leaseFor(s, s.items[0].command, "bob")
|
||||
if err != nil || l.remote.String() != "10.77.0.11" {
|
||||
t.Fatalf("after a close: %v %v", l, err)
|
||||
}
|
||||
v := map[string]string{}
|
||||
env := l.add(v, nil)
|
||||
got := config.Expand(s.items[0].command, v, nil)
|
||||
if got != "pppd 10.77.0.1:10.77.0.11 ms-dns 10.77.0.1 ms-dns 9.9.9.9" {
|
||||
t.Errorf("command: %s", got)
|
||||
}
|
||||
if !strings.Contains(strings.Join(env, " "), "MODEM_PPP_REMOTE=10.77.0.11") {
|
||||
t.Errorf("env: %v", env)
|
||||
}
|
||||
// a command without the placeholders takes nothing
|
||||
if l, err := leaseFor(s, "pppd 1.2.3.4:5.6.7.8", "carol"); l != nil || err != nil {
|
||||
t.Errorf("no placeholders: %v %v", l, err)
|
||||
}
|
||||
}
|
||||
|
||||
// one DNS server: {ppp_dns2} repeats it, so ms-dns always has one
|
||||
func TestPPPPoolOneDNS(t *testing.T) {
|
||||
s, err := poolConf(t, "local = 10.77.0.1\nrange = 10.77.0.10-10.77.0.20", "pppd {ppp_remote}")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
l, err := takeAddress(&s.pppPool, s.limits.stateDir, "x")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer l.close()
|
||||
if v := l.vars(); v["ppp_dns"] != "10.77.0.1" || v["ppp_dns2"] != "10.77.0.1" {
|
||||
t.Errorf("dns defaults to local: %v", v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPPPPoolSettings(t *testing.T) {
|
||||
for pool, want := range map[string]string{
|
||||
"range = 10.77.0.10": "first-last",
|
||||
"range = 10.77.0.20-10": "comes before",
|
||||
"range = 10.77.0.10-20": "local:",
|
||||
"local = 10.77.0.15\nrange = 10.77.0.10-20": "in the range",
|
||||
"local = 10.77.0.1\nrange = 10.77.0.10-10.78.0.10": "at most",
|
||||
"local = 10.77.0.1\nrange = fe80::1-2": "not an IPv4",
|
||||
"local = 10.77.0.1\nrange = 10.77.0.10-20\ndns = a": "dns",
|
||||
"local = 10.77.0.1\nrange = 10.77.0.10-20\ndns = 1.1.1.1 8.8.8.8 9.9.9.9": "at most 2",
|
||||
} {
|
||||
if _, err := poolConf(t, pool, "pppd {ppp_remote}"); err == nil || !strings.Contains(err.Error(), want) {
|
||||
t.Errorf("%q: %v, want %q", pool, err, want)
|
||||
}
|
||||
}
|
||||
// a command naming the pool, with no pool
|
||||
if _, err := poolConf(t, "", "pppd {ppp_remote}"); err == nil || !strings.Contains(err.Error(), "needs [ppp_pool]") {
|
||||
t.Errorf("no pool: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -90,6 +90,7 @@ type settings struct {
|
||||
limits limitSettings
|
||||
dropfile dropfileSettings
|
||||
autoppp autopppSettings
|
||||
pppPool pppPoolSettings
|
||||
terminal terminalSettings
|
||||
authd *authdSettings // nil: no auth socket
|
||||
menuTitle string
|
||||
@@ -184,6 +185,9 @@ func loadSettings(path string) (*settings, error) {
|
||||
if s.autoppp, err = loadAutoPPP(c.Section("autoppp")); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.pppPool, err = loadPPPPool(c.Section("ppp_pool")); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.terminal, err = loadTerminal(c.Section("terminal")); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -241,6 +245,9 @@ func loadSettings(path string) (*settings, error) {
|
||||
if err := checkDropfiles(s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := checkPool(s); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s.autoppp.item != "" && s.selects(strings.ToUpper(s.autoppp.item)) == nil {
|
||||
return nil, fmt.Errorf("[autoppp] item: no item %q", s.autoppp.item)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
# /etc/modemmenu/dialup.conf: the dial-up callers' network, read by
|
||||
# modemmenu-dialup (at boot, by modemmenu-dialup.service) and by pppd's
|
||||
# ip-up.d/ip-down.d hooks. Shell syntax.
|
||||
#
|
||||
# Callers get addresses from modemmenu's [ppp_pool] in SUBNET, in a
|
||||
# routing table of their own (a VRF), so that the host's own networks are
|
||||
# not theirs: they reach the host's services on SERVER_ADDR (the ports
|
||||
# below), the internet through EGRESS, and of the host's LANs only what
|
||||
# ALLOW_CIDRS lets through.
|
||||
|
||||
# the VRF device and its routing table
|
||||
VRF=dialup
|
||||
VRF_TABLE=77
|
||||
|
||||
# the callers' subnet: [ppp_pool] range is in it, and its local is
|
||||
# SERVER_ADDR. Pick one no network of the host uses.
|
||||
SUBNET=10.77.0.0/24
|
||||
SERVER_ADDR=10.77.0.1
|
||||
|
||||
# Where the callers' traffic leaves:
|
||||
# vlan a VLAN of its own on UPLINK (UPLINK.VLAN_ID), with its own
|
||||
# address and gateway: dial-up never shares the host's LAN
|
||||
# uplink out of UPLINK, through the host's gateway (NAT), filtered
|
||||
# none no internet: the host's services only
|
||||
EGRESS=uplink
|
||||
UPLINK=eth0
|
||||
|
||||
# EGRESS=vlan: the VLAN, this host's address on it, its router
|
||||
VLAN_ID=77
|
||||
VLAN_ADDR=10.177.0.2/24
|
||||
VLAN_GATEWAY=10.177.0.1
|
||||
|
||||
# EGRESS=uplink: the gateway ("": the host's default gateway on UPLINK)
|
||||
UPLINK_GATEWAY=
|
||||
|
||||
# masquerade the callers behind the egress address (no: the router on the
|
||||
# VLAN routes SUBNET back to VLAN_ADDR itself)
|
||||
NAT=yes
|
||||
|
||||
# What callers may reach. BLOCK_CIDRS are dropped (the private ranges by
|
||||
# default, so the host's LANs and the other callers are out of reach),
|
||||
# except ALLOW_CIDRS, which the sysop opens, e.g. ALLOW_CIDRS="192.168.1.20/32"
|
||||
# for one machine, or SUBNET for callers to reach each other. The
|
||||
# internet (anything else) is open while INTERNET=yes.
|
||||
ALLOW_CIDRS=""
|
||||
BLOCK_CIDRS="10.0.0.0/8 172.16.0.0/12 192.168.0.0/16 100.64.0.0/10 169.254.0.0/16 224.0.0.0/4 240.0.0.0/4"
|
||||
INTERNET=yes
|
||||
|
||||
# the host's services callers may use on SERVER_ADDR: DNS (the resolver
|
||||
# of modemmenu-dns.service), telnet, HTTP(S), MSN 1863, Yahoo 5050,
|
||||
# OSCAR/AOL 5190. The host's other ports are closed to them.
|
||||
HOST_TCP_PORTS="53 23 80 443 1863 5050 5190"
|
||||
HOST_UDP_PORTS="53"
|
||||
@@ -0,0 +1,27 @@
|
||||
# /etc/modemmenu/dns.d/services.conf: the old services' names, answered
|
||||
# with this system's address so that the callers' unchanged clients reach
|
||||
# our front ends. address=/name/ip also answers every name under it.
|
||||
# Uncomment a service once its front end runs; a front end may instead
|
||||
# drop a file of its own here (dns.d/NAME.conf). After a change:
|
||||
# systemctl reload modemmenu-dns
|
||||
|
||||
# AIM and ICQ (OSCAR, TCP 5190)
|
||||
#address=/login.oscar.aol.com/10.77.0.1
|
||||
#address=/login.icq.com/10.77.0.1
|
||||
|
||||
# AOL's client (TCP 5190)
|
||||
#address=/americaonline.aol.com/10.77.0.1
|
||||
|
||||
# MSN Messenger (TCP 1863), WebTV's Messenger too
|
||||
#address=/messenger.hotmail.com/10.77.0.1
|
||||
|
||||
# Yahoo! Messenger: the pager (TCP 5050, then 23, 25, 80), the capacity
|
||||
# lookup, rooms and files (HTTP); login.yahoo.com is Y!M 9's HTTPS login
|
||||
#address=/scs.msg.yahoo.com/10.77.0.1
|
||||
#address=/scsa.msg.yahoo.com/10.77.0.1
|
||||
#address=/vcs1.msg.yahoo.com/10.77.0.1
|
||||
#address=/vcs2.msg.yahoo.com/10.77.0.1
|
||||
#address=/insider.msg.yahoo.com/10.77.0.1
|
||||
#address=/filetransfer.msg.yahoo.com/10.77.0.1
|
||||
#address=/relay.msg.yahoo.com/10.77.0.1
|
||||
#address=/login.yahoo.com/10.77.0.1
|
||||
@@ -0,0 +1,27 @@
|
||||
# /etc/modemmenu/dnsmasq.conf: the dial-up callers' DNS server, run by
|
||||
# modemmenu-dns.service in their VRF. [ppp_pool] dns (ms-dns) points
|
||||
# callers here. A DNS server only: no DHCP (PPP's IPCP gives the
|
||||
# addresses).
|
||||
|
||||
# on the callers' side only (dialup.conf's SERVER_ADDR), never the host's
|
||||
# own networks
|
||||
listen-address=10.77.0.1
|
||||
bind-interfaces
|
||||
pid-file=/run/modemmenu-dns.pid
|
||||
|
||||
# upstream: these, not the host's resolv.conf (its 127.0.0.53 is not in
|
||||
# the VRF)
|
||||
no-resolv
|
||||
server=9.9.9.9
|
||||
server=1.1.1.1
|
||||
domain-needed
|
||||
bogus-priv
|
||||
cache-size=1000
|
||||
|
||||
# names of this system: bbs.dialup and the like, answered here only
|
||||
local=/dialup/
|
||||
address=/bbs.dialup/10.77.0.1
|
||||
|
||||
# the overrides for the services we provide: every *.conf here
|
||||
# (services.conf, and a file per front end)
|
||||
conf-dir=/etc/modemmenu/dns.d/,*.conf
|
||||
Executable
+9
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
# /etc/ppp/ip-down.d/modemmenu-dialup: the link's name off the firewall's
|
||||
# list, for the next link of that name
|
||||
CONF=/etc/modemmenu/dialup.conf
|
||||
[ -r "$CONF" ] || exit 0
|
||||
# shellcheck source=/dev/null
|
||||
. "$CONF"
|
||||
[ "${PPP_LOCAL:-}" = "$SERVER_ADDR" ] || exit 0
|
||||
exec /usr/local/sbin/modemmenu-dialup detach "$PPP_IFACE"
|
||||
Executable
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
# /etc/ppp/ip-up.d/modemmenu-dialup: a dial-up caller's link (its local
|
||||
# address is dialup.conf's SERVER_ADDR) into the callers' VRF and
|
||||
# firewall; pppd's other links are left alone
|
||||
CONF=/etc/modemmenu/dialup.conf
|
||||
[ -r "$CONF" ] || exit 0
|
||||
# shellcheck source=/dev/null
|
||||
. "$CONF"
|
||||
[ "${PPP_LOCAL:-}" = "$SERVER_ADDR" ] || exit 0
|
||||
exec /usr/local/sbin/modemmenu-dialup attach "$PPP_IFACE"
|
||||
Executable
+165
@@ -0,0 +1,165 @@
|
||||
#!/bin/bash
|
||||
# modemmenu-dialup: the dial-up callers' network (dialup.conf)
|
||||
#
|
||||
# modemmenu-dialup up the VRF, its egress, the firewall, sysctls
|
||||
# modemmenu-dialup down all of it removed
|
||||
# modemmenu-dialup attach IF a caller's PPP link into it (ip-up.d)
|
||||
# modemmenu-dialup detach IF and out again (ip-down.d)
|
||||
# modemmenu-dialup status what is there
|
||||
#
|
||||
# Copyright (C) 2026 D-Modem Authors
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
set -eu
|
||||
|
||||
CONF=${MODEMMENU_DIALUP_CONF:-/etc/modemmenu/dialup.conf}
|
||||
# shellcheck source=/dev/null
|
||||
. "$CONF"
|
||||
VRF=${VRF:-dialup} VRF_TABLE=${VRF_TABLE:-77}
|
||||
DUMMY=${VRF}0
|
||||
NFT_TABLE=modemmenu_dialup
|
||||
|
||||
die() { echo "modemmenu-dialup: $*" >&2; exit 1; }
|
||||
|
||||
# the interface the callers' traffic leaves by ("" for none)
|
||||
egress_if() {
|
||||
case $EGRESS in
|
||||
vlan) echo "$UPLINK.$VLAN_ID" ;;
|
||||
uplink) echo "$UPLINK" ;;
|
||||
none) echo "" ;;
|
||||
*) die "EGRESS=$EGRESS (vlan, uplink or none)" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
# a list of words as an nft set's elements
|
||||
elems() { echo "$*" | tr -s ' \t' ',' | sed 's/^,//; s/,$//'; }
|
||||
|
||||
firewall() {
|
||||
local out allow block tcp udp internet=""
|
||||
out=$(egress_if)
|
||||
# shellcheck disable=SC2153 # INTERNET is dialup.conf's
|
||||
[ -z "$out" ] || [ "$INTERNET" != yes ] || internet="oifname \"$out\" accept"
|
||||
allow=$(elems "$ALLOW_CIDRS") block=$(elems "$BLOCK_CIDRS")
|
||||
tcp=$(elems "$HOST_TCP_PORTS") udp=$(elems "$HOST_UDP_PORTS")
|
||||
nft delete table inet $NFT_TABLE 2>/dev/null || true
|
||||
nft -f - <<NFT
|
||||
table inet $NFT_TABLE {
|
||||
# the callers' links, added and removed by ip-up.d / ip-down.d, and
|
||||
# the VRF device (the kernel names it as the way in of what it routes)
|
||||
set links { type ifname; elements = { "$VRF" } }
|
||||
set allow { type ipv4_addr; flags interval; ${allow:+elements = { $allow }} }
|
||||
set block { type ipv4_addr; flags interval; ${block:+elements = { $block }} }
|
||||
set tcp_ports { type inet_service; ${tcp:+elements = { $tcp }} }
|
||||
set udp_ports { type inet_service; ${udp:+elements = { $udp }} }
|
||||
|
||||
chain input {
|
||||
type filter hook input priority filter - 1; policy accept;
|
||||
iifname != @links return
|
||||
ct state established,related accept
|
||||
ip saddr != $SUBNET drop
|
||||
meta l4proto icmp icmp type echo-request accept
|
||||
ip daddr $SERVER_ADDR tcp dport @tcp_ports accept
|
||||
ip daddr $SERVER_ADDR udp dport @udp_ports accept
|
||||
drop
|
||||
}
|
||||
chain forward {
|
||||
type filter hook forward priority filter - 1; policy accept;
|
||||
iifname != @links return
|
||||
ct state established,related accept
|
||||
meta nfproto ipv6 drop
|
||||
ip saddr != $SUBNET drop
|
||||
ip daddr @allow accept
|
||||
ip daddr @block drop
|
||||
$internet
|
||||
drop
|
||||
}
|
||||
}
|
||||
NFT
|
||||
nft delete table ip ${NFT_TABLE}_nat 2>/dev/null || true
|
||||
if [ -n "$out" ] && [ "$NAT" = yes ]; then
|
||||
nft -f - <<NFT
|
||||
table ip ${NFT_TABLE}_nat {
|
||||
chain postrouting {
|
||||
type nat hook postrouting priority srcnat; policy accept;
|
||||
oifname "$out" ip saddr $SUBNET masquerade
|
||||
}
|
||||
}
|
||||
NFT
|
||||
fi
|
||||
}
|
||||
|
||||
up() {
|
||||
down 2>/dev/null || true
|
||||
sysctl -qw net.ipv4.ip_forward=1
|
||||
# sockets of the host's services (bound in no VRF) answer the callers
|
||||
sysctl -qw net.ipv4.tcp_l3mdev_accept=1 net.ipv4.udp_l3mdev_accept=1
|
||||
|
||||
ip link add "$VRF" type vrf table "$VRF_TABLE"
|
||||
ip link set "$VRF" up
|
||||
# nothing found in the VRF's table: unreachable, never the host's table
|
||||
ip route add unreachable default metric 4278198272 vrf "$VRF"
|
||||
# SERVER_ADDR, there while no caller is: the DNS server binds to it
|
||||
ip link add "$DUMMY" type dummy
|
||||
ip link set "$DUMMY" master "$VRF"
|
||||
ip addr add "$SERVER_ADDR/32" dev "$DUMMY"
|
||||
ip link set "$DUMMY" up
|
||||
|
||||
case $EGRESS in
|
||||
vlan)
|
||||
ip link add link "$UPLINK" name "$UPLINK.$VLAN_ID" type vlan id "$VLAN_ID"
|
||||
ip link set "$UPLINK.$VLAN_ID" master "$VRF"
|
||||
ip addr add "$VLAN_ADDR" dev "$UPLINK.$VLAN_ID"
|
||||
ip link set "$UPLINK.$VLAN_ID" up
|
||||
ip route add default via "$VLAN_GATEWAY" vrf "$VRF"
|
||||
;;
|
||||
uplink)
|
||||
local gw=$UPLINK_GATEWAY
|
||||
[ -n "$gw" ] || gw=$(ip -4 route show default dev "$UPLINK" | awk '{print $3; exit}')
|
||||
[ -n "$gw" ] || die "no default gateway on $UPLINK: set UPLINK_GATEWAY"
|
||||
# out by the host's uplink (a route leak out of the VRF), and the
|
||||
# answers, once NAT gives them back their caller's address, in
|
||||
ip route add default via "$gw" dev "$UPLINK" table "$VRF_TABLE"
|
||||
ip route add "$SUBNET" dev "$VRF"
|
||||
;;
|
||||
none) ;;
|
||||
*) die "EGRESS=$EGRESS (vlan, uplink or none)" ;;
|
||||
esac
|
||||
firewall
|
||||
}
|
||||
|
||||
down() {
|
||||
nft delete table inet $NFT_TABLE 2>/dev/null || true
|
||||
nft delete table ip ${NFT_TABLE}_nat 2>/dev/null || true
|
||||
ip route del "$SUBNET" dev "$VRF" 2>/dev/null || true
|
||||
[ "$EGRESS" != vlan ] || ip link del "$UPLINK.$VLAN_ID" 2>/dev/null || true
|
||||
ip link del "$DUMMY" 2>/dev/null || true
|
||||
ip link del "$VRF" 2>/dev/null || true
|
||||
}
|
||||
|
||||
attach() {
|
||||
ip link show "$VRF" >/dev/null 2>&1 || die "no $VRF: modemmenu-dialup up first"
|
||||
# filtered first, then moved: the link is never open
|
||||
nft add element inet $NFT_TABLE links "{ $1 }"
|
||||
ip link set dev "$1" master "$VRF"
|
||||
}
|
||||
|
||||
detach() {
|
||||
nft delete element inet $NFT_TABLE links "{ $1 }" 2>/dev/null || true
|
||||
}
|
||||
|
||||
status() {
|
||||
ip -d link show "$VRF" 2>/dev/null || echo "no $VRF"
|
||||
echo "--- table $VRF_TABLE"
|
||||
ip route show vrf "$VRF" 2>/dev/null || true
|
||||
echo "--- links"
|
||||
ip -br link show master "$VRF" 2>/dev/null || true
|
||||
nft list set inet $NFT_TABLE links 2>/dev/null || true
|
||||
}
|
||||
|
||||
case ${1:-} in
|
||||
up) up ;;
|
||||
down) down ;;
|
||||
attach) [ -n "${2:-}" ] || die "attach IFACE"; attach "$2" ;;
|
||||
detach) [ -n "${2:-}" ] || die "detach IFACE"; detach "$2" ;;
|
||||
status) status ;;
|
||||
*) echo "usage: modemmenu-dialup up|down|status|attach IFACE|detach IFACE" >&2; exit 2 ;;
|
||||
esac
|
||||
@@ -0,0 +1,15 @@
|
||||
# the dial-up callers' network: VRF, egress, firewall (dialup.conf)
|
||||
[Unit]
|
||||
Description=modemmenu dial-up network
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
Before=modemmenu.service modemmenu-dns.service
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
RemainAfterExit=yes
|
||||
ExecStart=/usr/local/sbin/modemmenu-dialup up
|
||||
ExecStop=/usr/local/sbin/modemmenu-dialup down
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,14 @@
|
||||
# the dial-up callers' DNS server: dnsmasq in their VRF, on SERVER_ADDR,
|
||||
# with the service overrides of /etc/modemmenu/dns.d
|
||||
[Unit]
|
||||
Description=modemmenu dial-up DNS
|
||||
Requires=modemmenu-dialup.service
|
||||
After=modemmenu-dialup.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/sbin/ip vrf exec dialup /usr/sbin/dnsmasq --keep-in-foreground --conf-file=/etc/modemmenu/dnsmasq.conf
|
||||
ExecReload=/bin/kill -HUP $MAINPID
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -29,6 +29,7 @@ One Go module, one program:
|
||||
| `internal/telnet/` | the telnet client of `mode = telnet` items |
|
||||
| `authd/` | the auth socket's protocol and a client, for other programs (a BBS) to import |
|
||||
| `pppd/` | pppd's `modemmenu.so` plugin, in C |
|
||||
| `dialup/` | the PPP callers' network: VRF, firewall, DNS with overrides (`make install-dialup`) |
|
||||
| `samples/` | modemmenu.conf, the users file, PAM and systemd samples |
|
||||
| `freepbx/` | the FreePBX setup |
|
||||
| `tools/confref/` | makes docs/reference.md from samples/modemmenu.conf.sample |
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
# The dial-up network
|
||||
|
||||
PPP callers get an address of their own from modemmenu's `[ppp_pool]`,
|
||||
a DNS server that answers for the services this system provides, and a
|
||||
network of their own: they reach the host's services, the internet, and
|
||||
none of the host's LANs unless the sysop opens a range for them. The
|
||||
files are in [`dialup/`](../dialup); `make install-dialup` installs them.
|
||||
|
||||
```
|
||||
caller ── modem ── D-Modem ── modemmenu ── pppd ── ppp0 ┐
|
||||
│ VRF "dialup" (table 77)
|
||||
10.77.0.1: DNS, BBS, front ends ─┤ 10.77.0.0/24
|
||||
└─ egress: eth0.77 (VLAN), eth0 (NAT) or none
|
||||
```
|
||||
|
||||
## Addresses: `[ppp_pool]`
|
||||
|
||||
```
|
||||
[ppp_pool]
|
||||
local = 10.77.0.1
|
||||
range = 10.77.0.10-10.77.0.250
|
||||
;dns = 10.77.0.1
|
||||
```
|
||||
|
||||
A PPP command that names `{ppp_remote}` (or `{ppp_local}`, `{ppp_dns}`,
|
||||
`{ppp_dns2}`) takes the first free address of `range` before pppd
|
||||
starts, and gives it back when pppd ends:
|
||||
|
||||
```
|
||||
command = exec /usr/sbin/pppd nodetach noauth local lock passive {ppp_local}:{ppp_remote} ms-dns {ppp_dns} ms-dns {ppp_dns2} ipparam {user}
|
||||
```
|
||||
|
||||
- Each address is a lock file in `state_dir/ppp-pool`, held while pppd
|
||||
runs and holding the user's name and modemmenu's pid. A modemmenu per
|
||||
call and every session of `modemmenu -serve` share them, and an
|
||||
address frees itself when its modemmenu dies.
|
||||
- PPP gives the addresses (IPCP), not DHCP. `local` is the server's end
|
||||
of every link; `dns` is what `ms-dns` offers (`local` by default).
|
||||
`{ppp_dns2}` is the second server, or the first again, so the command
|
||||
always has two.
|
||||
- pppd's scripts see `MODEM_PPP_LOCAL`, `MODEM_PPP_REMOTE`,
|
||||
`MODEM_PPP_DNS` and `MODEM_PPP_DNS2`.
|
||||
- A full pool refuses the call ("all N PPP addresses are in use").
|
||||
- D-Modem's own `[ppp]` profile runs pppd without modemmenu, so it has
|
||||
no pool: give it a fixed pair outside `range` (10.77.0.2 to .9).
|
||||
|
||||
Pick a subnet none of the host's networks use. 10.77.0.0/24 is the
|
||||
sample's.
|
||||
|
||||
## Isolation: `modemmenu-dialup`
|
||||
|
||||
`modemmenu-dialup up` (run at boot by `modemmenu-dialup.service`) sets
|
||||
up, from `/etc/modemmenu/dialup.conf`:
|
||||
|
||||
- **A VRF**, `dialup`, with routing table 77. The callers' links live in
|
||||
it, so the host's routes, and its LANs, are not theirs. A lookup that
|
||||
finds nothing there is unreachable; it never falls through to the
|
||||
host's table.
|
||||
- **`dialup0`**, a dummy interface holding `SERVER_ADDR` (10.77.0.1), so
|
||||
the DNS server has its address while no caller is on.
|
||||
- **An egress** (`EGRESS`):
|
||||
- `vlan`: `UPLINK.VLAN_ID` (`eth0.77`), in the VRF, with its own
|
||||
address and gateway. Dial-up traffic leaves on a VLAN of its own and
|
||||
never shares the host's LAN. `NAT=no` when the router on that VLAN
|
||||
routes 10.77.0.0/24 back itself.
|
||||
- `uplink`: out of the host's interface through its gateway,
|
||||
masqueraded. Simpler, and filtered like the VLAN.
|
||||
- `none`: no internet; the host's services only.
|
||||
- **A firewall** (nftables table `modemmenu_dialup`) on the callers'
|
||||
links:
|
||||
- to the host: only `HOST_TCP_PORTS` and `HOST_UDP_PORTS` on
|
||||
`SERVER_ADDR` (DNS, telnet, HTTP(S), MSN 1863, Yahoo 5050, OSCAR and
|
||||
AOL 5190 by default), and ping. SSH, the PBX's web UI and every other
|
||||
port of the host are closed to them.
|
||||
- onward: `BLOCK_CIDRS` are dropped (every private range, link-local
|
||||
and multicast, by default), so the host's LANs, and the other callers,
|
||||
are out of reach, except `ALLOW_CIDRS`, which the sysop opens:
|
||||
|
||||
```
|
||||
ALLOW_CIDRS="192.168.1.20/32" # one machine on the LAN
|
||||
ALLOW_CIDRS="192.168.1.0/24 10.77.0.0/24" # a LAN, and caller to caller
|
||||
```
|
||||
|
||||
The rest, the internet, is open while `INTERNET=yes`.
|
||||
- a source address outside `SUBNET` is dropped, and IPv6 too.
|
||||
- `net.ipv4.ip_forward=1`, and `tcp_l3mdev_accept`/`udp_l3mdev_accept`,
|
||||
so the host's services (listening in no VRF) answer callers on
|
||||
10.77.0.1.
|
||||
|
||||
pppd's `ip-up.d/modemmenu-dialup` moves a link whose local address is
|
||||
`SERVER_ADDR` into the VRF, putting it on the firewall's list first;
|
||||
`ip-down.d` takes its name off again. pppd's other links are left
|
||||
alone. After editing `dialup.conf`, `systemctl restart
|
||||
modemmenu-dialup modemmenu-dns`. `modemmenu-dialup status` shows the
|
||||
VRF, its routes and the callers' links.
|
||||
|
||||
## DNS: `modemmenu-dns`
|
||||
|
||||
`modemmenu-dns.service` runs dnsmasq inside the VRF, on 10.77.0.1 only,
|
||||
with [`dnsmasq.conf`](../dialup/dnsmasq.conf): no DHCP, upstream
|
||||
servers of its own (the host's `127.0.0.53` is not in the VRF), and the
|
||||
names of this system under `.dialup` (`bbs.dialup`).
|
||||
|
||||
**Overrides** are every `*.conf` in `/etc/modemmenu/dns.d/`.
|
||||
[`services.conf`](../dialup/dns.d/services.conf) has the old services'
|
||||
names ready to uncomment as their front ends come up: AIM and ICQ
|
||||
(`login.oscar.aol.com`), AOL (`americaonline.aol.com`), MSN Messenger
|
||||
(`messenger.hotmail.com`) and Yahoo! Messenger (`scs.msg.yahoo.com` and
|
||||
the rest). A front end can drop its own file instead:
|
||||
|
||||
```
|
||||
# /etc/modemmenu/dns.d/oscar.conf
|
||||
address=/login.oscar.aol.com/10.77.0.1
|
||||
```
|
||||
|
||||
`address=/name/ip` answers the name and every name under it. Then
|
||||
`systemctl reload modemmenu-dns`. Callers' clients connect to our front
|
||||
ends with no hosts file or registry change.
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
apt install ppp dnsmasq-base nftables iproute2
|
||||
make install-dialup # the script, hooks, units, /etc/modemmenu/{dialup.conf,dnsmasq.conf,dns.d/}
|
||||
$EDITOR /etc/modemmenu/dialup.conf
|
||||
systemctl enable --now modemmenu-dialup modemmenu-dns
|
||||
```
|
||||
|
||||
Then give modemmenu.conf the `[ppp_pool]` above (the samples have it)
|
||||
and the PPP commands their `{ppp_...}` placeholders.
|
||||
|
||||
## Limits
|
||||
|
||||
- IPv4 only. IPv6 from callers is dropped.
|
||||
- The VRF needs a kernel with `CONFIG_NET_VRF` (Debian's and Ubuntu's
|
||||
have it) and `ip vrf exec` needs cgroup v2.
|
||||
- `dnsmasq.conf`'s `listen-address`, `address=` lines and the unit's VRF
|
||||
name are written for the defaults: change them with `SERVER_ADDR` and
|
||||
`VRF`.
|
||||
+11
-3
@@ -12,7 +12,7 @@ on the line instead:
|
||||
```
|
||||
[autoppp]
|
||||
enabled = yes
|
||||
command = exec /usr/sbin/pppd nodetach lock passive local 192.168.77.1:192.168.77.2 ms-dns 192.168.77.1 require-pap refuse-chap refuse-mschap refuse-mschap-v2 refuse-eap plugin modemmenu.so ipparam autoppp
|
||||
command = exec /usr/sbin/pppd nodetach lock passive local {ppp_local}:{ppp_remote} ms-dns {ppp_dns} ms-dns {ppp_dns2} require-pap refuse-chap refuse-mschap refuse-mschap-v2 refuse-eap plugin modemmenu.so ipparam autoppp
|
||||
item = ppp
|
||||
```
|
||||
|
||||
@@ -39,7 +39,15 @@ caller ID, the rate).
|
||||
network that was the line's privacy; over SIP it is in the call's RTP:
|
||||
give the trunk SRTP (and SIP over TLS), or keep it on a network you
|
||||
trust.
|
||||
- **Fix the addresses** (`local:remote` on pppd's command line): the
|
||||
plugin lets the logged-in peer have the address pppd gives it.
|
||||
- **Fix the addresses** (`local:remote` on pppd's command line, from
|
||||
`[ppp_pool]`): the plugin lets the logged-in peer have the address pppd
|
||||
gives it.
|
||||
- The plugin is built for the pppd of the headers it is built against
|
||||
(`pppd_version`); rebuild it when pppd is upgraded.
|
||||
|
||||
## Addresses, DNS and the callers' network
|
||||
|
||||
Each PPP caller gets an address of its own from `[ppp_pool]`, a DNS
|
||||
server with overrides for the services this system provides, and a
|
||||
network kept apart from the host's: see
|
||||
[The dial-up network](dialup-network.md).
|
||||
+14
-3
@@ -23,6 +23,7 @@ full.
|
||||
| [`[sql]`](#sql) | SQL: query gets args (user, password, in that order of placeholders) and returns one column: the stored password, checked as hash says (auto: by its prefix as in [file]; or bcrypt, sha256, sha512, plain). |
|
||||
| [`[server]`](#server) | modemmenu -serve: one modemmenu for all calls, on a unix socket (or tcp:host:port). |
|
||||
| [`[authd]`](#authd) | The auth socket: the BBS's other logins (telnet, SSH, the web) ask the backends above for a user's password through it, so that it is the same one. |
|
||||
| [`[ppp_pool]`](#ppp_pool) | The PPP callers' addresses: a command that names {ppp_remote} (or {ppp_local}, {ppp_dns}, {ppp_dns2}) takes the first free address of range for the call, so that several lines run PPP at once, and gives it back when pppd ends. |
|
||||
| [`[autoppp]`](#autoppp) | AutoPPP: a dialer that starts PPP at once (Windows' Dial-Up Networking, most others) sends a PPP frame where the login prompt wants a name; then command runs on the line instead (pppd), and its modemmenu.so plugin (make builds it with ppp-dev's headers; make install puts it in pppd's plugin directory) asks this call's auth socket for the PAP login: the backends check it as at the prompt, then item's access rules, then the time limits, whose time left becomes pppd's maxconnect. |
|
||||
| [`[dropfile]`](#dropfile) | drop files for doors (an exec item's dropfile =): what they say of the BBS, and how the door reaches the caller. |
|
||||
| [`[menu]`](#menu) | The menu: its title, prompt, items and the words that hang up. |
|
||||
@@ -200,14 +201,24 @@ The auth socket: the BBS's other logins (telnet, SSH, the web) ask the backends
|
||||
| `allow_users` | `bbs` | See the section above. |
|
||||
| `max_clients` | `16` | requests at once. |
|
||||
|
||||
## `[ppp_pool]`
|
||||
|
||||
The PPP callers' addresses: a command that names {ppp_remote} (or {ppp_local}, {ppp_dns}, {ppp_dns2}) takes the first free address of range for the call, so that several lines run PPP at once, and gives it back when pppd ends. They are lock files in state_dir/ppp-pool (each with who has it), shared by every modemmenu on the host. local is the server's end of every link; dns, the DNS servers offered (ms-dns), local by default (the resolver of dialup/: docs/dialup-network.md). Pick a subnet none of the host's networks use. No range: no pool. The scripts see MODEM_PPP_LOCAL, MODEM_PPP_REMOTE, MODEM_PPP_DNS and MODEM_PPP_DNS2.
|
||||
|
||||
| key | sample | what it does |
|
||||
|---|---|---|
|
||||
| `local` | `10.77.0.1` | See the section above. |
|
||||
| `range` | `10.77.0.10-10.77.0.250` | See the section above. |
|
||||
| `dns` | `10.77.0.1` | See the section above. |
|
||||
|
||||
## `[autoppp]`
|
||||
|
||||
AutoPPP: a dialer that starts PPP at once (Windows' Dial-Up Networking, most others) sends a PPP frame where the login prompt wants a name; then command runs on the line instead (pppd), and its modemmenu.so plugin (make builds it with ppp-dev's headers; make install puts it in pppd's plugin directory) asks this call's auth socket for the PAP login: the backends check it as at the prompt, then item's access rules, then the time limits, whose time left becomes pppd's maxconnect. PAP only: CHAP needs the passwords kept where they can be read back. Fix the addresses (local:remote): the plugin lets the peer have the one pppd gives it.
|
||||
AutoPPP: a dialer that starts PPP at once (Windows' Dial-Up Networking, most others) sends a PPP frame where the login prompt wants a name; then command runs on the line instead (pppd), and its modemmenu.so plugin (make builds it with ppp-dev's headers; make install puts it in pppd's plugin directory) asks this call's auth socket for the PAP login: the backends check it as at the prompt, then item's access rules, then the time limits, whose time left becomes pppd's maxconnect. PAP only: CHAP needs the passwords kept where they can be read back. Fix the addresses (local:remote, from [ppp_pool]): the plugin lets the peer have the one pppd gives it.
|
||||
|
||||
| key | sample | what it does |
|
||||
|---|---|---|
|
||||
| `enabled` | `no` | See the section above. |
|
||||
| `command` | `exec /usr/sbin/pppd nodetach lock passive local 192.168.77.1:192.168.77.2 ms-dns 192.168.77.1 require-pap refuse-chap refuse-mschap refuse-mschap-v2 refuse-eap plugin modemmenu.so ipparam autoppp` | See the section above. |
|
||||
| `command` | `exec /usr/sbin/pppd nodetach lock passive local {ppp_local}:{ppp_remote} ms-dns {ppp_dns} ms-dns {ppp_dns2} require-pap refuse-chap refuse-mschap refuse-mschap-v2 refuse-eap plugin modemmenu.so ipparam autoppp` | See the section above. |
|
||||
| `item` | `ppp` | the access rules (groups, min_baud, callerids...) a PPP login must pass. |
|
||||
|
||||
## `[dropfile]`
|
||||
@@ -276,7 +287,7 @@ There may be any number of these, each with its own NAME.
|
||||
| `rlogin_terminal` | `ansi/{baud}` | See the section above. |
|
||||
| `send` | `{user}\r{password}\r` | or a BBS that reads its login from the line: |
|
||||
| `time_warning` | `no` | no time warning in the middle of PPP's frames. |
|
||||
| `command` | `exec /usr/sbin/pppd nodetach noauth local lock passive 192.168.77.1:192.168.77.2 ms-dns 192.168.77.1 ipparam {user}` | no time warning in the middle of PPP's frames. Also: `exec "$SHELL" -l`, `cd /srv/doors/lord && exec dosemu -dumb -E "lord.bat $MODEM_NODE"`, `cd "$HOME/uploads" && exec rz -b -R -E`, `cd "$HOME" && exec kermit -Y -x`, `exec lynx -anonymous https://example.org/`, `exec mutt`, `exec tin -r`, `exec irssi -c 127.0.0.1 -n {user}`, `exec lynx -anonymous gopher://gopher.floodgap.com/`. |
|
||||
| `command` | `exec /usr/sbin/pppd nodetach noauth local lock passive {ppp_local}:{ppp_remote} ms-dns {ppp_dns} ms-dns {ppp_dns2} ipparam {user}` | no time warning in the middle of PPP's frames. Also: `exec "$SHELL" -l`, `cd /srv/doors/lord && exec dosemu -dumb -E "lord.bat $MODEM_NODE"`, `cd "$HOME/uploads" && exec rz -b -R -E`, `cd "$HOME" && exec kermit -Y -x`, `exec lynx -anonymous https://example.org/`, `exec mutt`, `exec tin -r`, `exec irssi -c 127.0.0.1 -n {user}`, `exec lynx -anonymous gopher://gopher.floodgap.com/`. |
|
||||
| `min_password` | `8` | See the section above. |
|
||||
| `path` | `/run/modemmenu/more.sock` | See the section above. |
|
||||
| `dropfile_dir` | `/srv/doors/lord/node{node}` | See the section above. |
|
||||
|
||||
+5
-4
@@ -100,10 +100,11 @@ detection off; D-Modem's line check page lists what is still in the way.
|
||||
|
||||
## The menu
|
||||
|
||||
- **PPP**: dial-up networking. `apt install ppp` first. The sample
|
||||
gives one pair of addresses (192.168.77.1 for the server, .2 for the
|
||||
caller), so one PPP caller at a time; forward or masquerade
|
||||
192.168.77.0/24 for the internet. Windows' Dial-Up Networking logs in
|
||||
- **PPP**: dial-up networking. `apt install ppp` first. Each caller
|
||||
gets an address of `[ppp_pool]` (10.77.0.10 to .250, the server is
|
||||
10.77.0.1). For DNS, the internet and keeping callers off your LAN,
|
||||
`make install-dialup` ([the dial-up network](../docs/dialup-network.md)).
|
||||
Windows' Dial-Up Networking logs in
|
||||
with PAP instead of at the prompt: turn on `[autoppp]` and install
|
||||
pppd's `modemmenu.so` plugin (`make` builds it when `ppp-dev` is
|
||||
installed).
|
||||
|
||||
@@ -82,13 +82,19 @@ header_timeout = 10
|
||||
trust_user = no
|
||||
max_sessions = 8
|
||||
|
||||
; the PPP callers' addresses, one each (several lines at once): see
|
||||
; docs/dialup-network.md for their network, DNS and firewall
|
||||
[ppp_pool]
|
||||
local = 10.77.0.1
|
||||
range = 10.77.0.10-10.77.0.250
|
||||
|
||||
; Windows' Dial-Up Networking starts PPP at once and logs in with PAP.
|
||||
; enabled = yes takes those callers to pppd, with the login checked against
|
||||
; the users file by pppd's modemmenu.so plugin (make builds it when ppp-dev
|
||||
; is installed)
|
||||
[autoppp]
|
||||
enabled = no
|
||||
command = exec /usr/sbin/pppd nodetach lock passive local 192.168.77.1:192.168.77.2 ms-dns 192.168.77.1 require-pap refuse-chap refuse-mschap refuse-mschap-v2 refuse-eap plugin modemmenu.so ipparam autoppp
|
||||
command = exec /usr/sbin/pppd nodetach lock passive local {ppp_local}:{ppp_remote} ms-dns {ppp_dns} ms-dns {ppp_dns2} require-pap refuse-chap refuse-mschap refuse-mschap-v2 refuse-eap plugin modemmenu.so ipparam autoppp
|
||||
item = ppp
|
||||
|
||||
[menu]
|
||||
@@ -100,8 +106,7 @@ hangup = G goodbye bye logoff
|
||||
hotkeys = no
|
||||
|
||||
; PPP: dial-up networking (apt install ppp). The caller has logged in
|
||||
; already, so noauth. The addresses are one pair: one PPP caller at a time,
|
||||
; or give each line its own pair
|
||||
; already, so noauth. Each caller gets an address of [ppp_pool]
|
||||
[item ppp]
|
||||
key = P
|
||||
aliases = dialup net
|
||||
@@ -109,7 +114,7 @@ label = PPP (dial-up networking)
|
||||
min_baud = 9600
|
||||
time_warning = no
|
||||
mode = exec
|
||||
command = exec /usr/sbin/pppd nodetach noauth local lock passive 192.168.77.1:192.168.77.2 ms-dns 192.168.77.1 ipparam {user}
|
||||
command = exec /usr/sbin/pppd nodetach noauth local lock passive {ppp_local}:{ppp_remote} ms-dns {ppp_dns} ms-dns {ppp_dns2} ipparam {user}
|
||||
|
||||
; who called last
|
||||
[item callers]
|
||||
|
||||
@@ -18,6 +18,7 @@ nav:
|
||||
- Configuration reference: reference.md
|
||||
- Authentication: authentication.md
|
||||
- PPP: ppp.md
|
||||
- Dial-up network: dialup-network.md
|
||||
- Security: security.md
|
||||
- Testing: testing.md
|
||||
- Documentation index: README.md
|
||||
@@ -252,6 +252,20 @@ max_sessions = 32
|
||||
; requests at once
|
||||
;max_clients = 16
|
||||
|
||||
; The PPP callers' addresses: a command that names {ppp_remote} (or
|
||||
; {ppp_local}, {ppp_dns}, {ppp_dns2}) takes the first free address of range
|
||||
; for the call, so that several lines run PPP at once, and gives it back when
|
||||
; pppd ends. They are lock files in state_dir/ppp-pool (each with who has
|
||||
; it), shared by every modemmenu on the host. local is the server's end of
|
||||
; every link; dns, the DNS servers offered (ms-dns), local by default (the
|
||||
; resolver of dialup/: docs/dialup-network.md). Pick a subnet none of the
|
||||
; host's networks use. No range: no pool. The scripts see MODEM_PPP_LOCAL,
|
||||
; MODEM_PPP_REMOTE, MODEM_PPP_DNS and MODEM_PPP_DNS2
|
||||
[ppp_pool]
|
||||
local = 10.77.0.1
|
||||
range = 10.77.0.10-10.77.0.250
|
||||
;dns = 10.77.0.1
|
||||
|
||||
; AutoPPP: a dialer that starts PPP at once (Windows' Dial-Up Networking,
|
||||
; most others) sends a PPP frame where the login prompt wants a name; then
|
||||
; command runs on the line instead (pppd), and its modemmenu.so plugin
|
||||
@@ -260,10 +274,11 @@ max_sessions = 32
|
||||
; backends check it as at the prompt, then item's access rules, then the
|
||||
; time limits, whose time left becomes pppd's maxconnect. PAP only: CHAP
|
||||
; needs the passwords kept where they can be read back. Fix the addresses
|
||||
; (local:remote): the plugin lets the peer have the one pppd gives it
|
||||
; (local:remote, from [ppp_pool]): the plugin lets the peer have the one
|
||||
; pppd gives it
|
||||
[autoppp]
|
||||
enabled = no
|
||||
command = exec /usr/sbin/pppd nodetach lock passive local 192.168.77.1:192.168.77.2 ms-dns 192.168.77.1 require-pap refuse-chap refuse-mschap refuse-mschap-v2 refuse-eap plugin modemmenu.so ipparam autoppp
|
||||
command = exec /usr/sbin/pppd nodetach lock passive local {ppp_local}:{ppp_remote} ms-dns {ppp_dns} ms-dns {ppp_dns2} require-pap refuse-chap refuse-mschap refuse-mschap-v2 refuse-eap plugin modemmenu.so ipparam autoppp
|
||||
; the access rules (groups, min_baud, callerids...) a PPP login must pass
|
||||
item = ppp
|
||||
|
||||
@@ -385,7 +400,8 @@ after = menu
|
||||
;send = "{user}\r{password}\r"
|
||||
|
||||
; PPP: pppd on the line. The caller is logged in already: noauth, and
|
||||
; ipparam hands the user to /etc/ppp/ip-up (as $6), which also sees MODEM_*
|
||||
; ipparam hands the user to /etc/ppp/ip-up (as $6), which also sees MODEM_*.
|
||||
; Each caller gets an address of [ppp_pool]
|
||||
[item ppp]
|
||||
key = P
|
||||
aliases = dialup net
|
||||
@@ -394,7 +410,7 @@ label = PPP (dial-up networking)
|
||||
; no time warning in the middle of PPP's frames
|
||||
time_warning = no
|
||||
mode = exec
|
||||
command = exec /usr/sbin/pppd nodetach noauth local lock passive 192.168.77.1:192.168.77.2 ms-dns 192.168.77.1 ipparam {user}
|
||||
command = exec /usr/sbin/pppd nodetach noauth local lock passive {ppp_local}:{ppp_remote} ms-dns {ppp_dns} ms-dns {ppp_dns2} ipparam {user}
|
||||
|
||||
; the caller's password changed where their account is: the users file,
|
||||
; SQL (update_query), LDAP (Password Modify, as the user) or the system
|
||||
|
||||
@@ -39,7 +39,7 @@ type key struct {
|
||||
}
|
||||
|
||||
var (
|
||||
headerRE = regexp.MustCompile(`^;?\[([a-z]+)(?:\s+(\S+))?\]$`)
|
||||
headerRE = regexp.MustCompile(`^;?\[([a-z_]+)(?:\s+(\S+))?\]$`)
|
||||
keyRE = regexp.MustCompile(`^(;?)([a-z][a-z0-9_]*)\s*=\s*(.*)$`)
|
||||
docKeyRE = regexp.MustCompile(`^;\s{2,4}([a-z][a-z0-9_]*) = (\S+)\s*(.*)$`)
|
||||
docMoreRE = regexp.MustCompile(`^;\s{5,}(.*)$`)
|
||||
|
||||
Reference in new issue
Block a user