Skip to content

Commit

Permalink
Sysctl keys can contain some more non-alphanumeric characters (#755)
Browse files Browse the repository at this point in the history
* Sysctl keys can contain some more non-alphanumeric characters like net.ipv4.conf.*.rp_filter = 2
* Support / in sysctl key, updated testsuite
  • Loading branch information
mchf authored Oct 24, 2022
1 parent a3ba6e2 commit e9c7ce3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 16 deletions.
14 changes: 13 additions & 1 deletion lenses/sysctl.aug
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,20 @@ let filter = incl "/boot/loader.conf"
(* View: comment *)
let comment = Util.comment_generic /[ \t]*[#;][ \t]*/ "# "

(* View: entry
basically a Simplevars.entry but key has to allow some special chars as '*' *)
let entry =
let some_value = Sep.space_equal . store Simplevars.to_comment_re
(* Rx.word extended by * and : *)
in let word = /[*:\/A-Za-z0-9_.-]+/
(* Avoid ambiguity in tree by making a subtree here *)
in let empty_value = [del /[ \t]*=/ "="] . store ""
in [ Util.indent . key word
. (some_value? | empty_value)
. (Util.eol | Util.comment_eol) ]

(* View: lns
The sysctl lens *)
let lns = (Util.empty | comment | Simplevars.entry)*
let lns = (Util.empty | comment | entry)*

let xfm = transform lns filter
36 changes: 36 additions & 0 deletions lenses/tests/test_sysctl.aug
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ kernel.sysrq = 0
net.ipv4.tcp_mem = \t393216 524288 786432
"

(* Variable: spec_chars_sysctl *)
let spec_chars_sysctl = "# Kernel sysctl configuration file
# Controls IP packet forwarding
net.ipv4.conf.*.rp_filter = 2
net.ipv4.conf.ib0:0.arp_filter = 1
"

(* Variable: slash_char_sysctl *)
let slash_in_sysctl_key = "# Kernel sysctl configuration file
# slash and dot can be interchanged
net/ipv4/conf/enp3s0.200/forwarding = 1
"

(* Test: Sysctl.lns *)
test Sysctl.lns get default_sysctl =
{ "#comment" = "Kernel sysctl configuration file" }
Expand All @@ -31,6 +44,19 @@ test Sysctl.lns get default_sysctl =
{ "#comment" = "Semicolon comments are also allowed" }
{ "net.ipv4.tcp_mem" = "393216 524288 786432" }

(* Test: Sysctl.lns *)
test Sysctl.lns get spec_chars_sysctl =
{ "#comment" = "Kernel sysctl configuration file" }
{ "#comment" = "Controls IP packet forwarding"}
{ "net.ipv4.conf.*.rp_filter" = "2" }
{ "net.ipv4.conf.ib0:0.arp_filter" = "1" }

(* Test: Sysctl.lns *)
test Sysctl.lns get slash_in_sysctl_key =
{ "#comment" = "Kernel sysctl configuration file" }
{ "#comment" = "slash and dot can be interchanged"}
{ "net/ipv4/conf/enp3s0.200/forwarding" = "1" }

(* Test: Sysctl.lns *)
test Sysctl.lns put default_sysctl after
set "net.ipv4.ip_forward" "1" ;
Expand All @@ -46,6 +72,16 @@ net.ipv4.ip_forward = 1
net.ipv4.tcp_mem = \t393216 524288 786432
"

(* Test: Sysctl.lns *)
test Sysctl.lns put spec_chars_sysctl after
set "net.ipv4.conf.*.rp_filter" "0" ;
set "net.ipv4.conf.ib0:0.arp_filter" "0"
= "# Kernel sysctl configuration file
# Controls IP packet forwarding
net.ipv4.conf.*.rp_filter = 0
net.ipv4.conf.ib0:0.arp_filter = 0
"

(* Local Variables: *)
(* mode: caml *)
(* End: *)
26 changes: 11 additions & 15 deletions man/augtool.1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" Automatically generated by Pod::Man 2.28 (Pod::Simple 3.31)
.\" Automatically generated by Pod::Man 4.09 (Pod::Simple 3.35)
.\"
.\" Standard preamble:
.\" ========================================================================
Expand Down Expand Up @@ -46,28 +46,24 @@
.ie \n(.g .ds Aq \(aq
.el .ds Aq '
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" If the F register is >0, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.\"
.\" Avoid warning from groff about undefined register 'F'.
.de IX
..
.nr rF 0
.if \n(.g .if rF .nr rF 1
.if (\n(rF:(\n(.g==0)) \{
. if \nF \{
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
.if !\nF .nr F 0
.if \nF>0 \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. if !\nF==2 \{
. nr % 0
. nr F 2
. \}
. if !\nF==2 \{\
. nr % 0
. nr F 2
. \}
.\}
.rr rF
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
Expand Down Expand Up @@ -133,7 +129,7 @@
.\" ========================================================================
.\"
.IX Title "AUGTOOL 1"
.TH AUGTOOL 1 "2016-08-05" "Augeas 1.5.0" "Augeas"
.TH AUGTOOL 1 "2021-05-26" "Augeas 1.13.0" "Augeas"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down Expand Up @@ -275,7 +271,7 @@ Parse \s-1NODE\s0 using \s-1LENS\s0 and store the resulting tree at \s-1PATH.\s0
Add a transform for \s-1FILE\s0 using \s-1LENS.\s0 The \s-1LENS\s0 may be a module name or a
full lens name. If a module name is given, then \*(L"lns\*(R" will be the lens
assumed. The \s-1FILTER\s0 must be either \*(L"incl\*(R" or \*(L"excl\*(R". If the filter is
\&\*(L"incl\*(R", the \s-1FILE\s0 will be parsed by the \s-1LENS. \s0 If the filter is \*(L"excl\*(R",
\&\*(L"incl\*(R", the \s-1FILE\s0 will be parsed by the \s-1LENS.\s0 If the filter is \*(L"excl\*(R",
the \s-1FILE\s0 will be excluded from the \s-1LENS. FILE\s0 may contain wildcards.
.IP "\fBload-file\fR <\s-1FILE\s0>" 4
.IX Item "load-file <FILE>"
Expand Down

0 comments on commit e9c7ce3

Please sign in to comment.