I'm writing a script* to parse IP sets, specifically ASNs.
Originally I had listed the resolved IP ranges each in list entry
options until I remembered that, even if less often, it will be needed to keep them up to date. I was nearly done.
So, to process them in place** either I finally get around learning awk
— pass. — or I save them to files in a directory where they can be updated easily. I was about to do just that when mt floppy turned solid state again, but to implement such idea I would need to be able to specify option loadfile
multiple times per IP set.
Once again. This was/is the output of what I thought was a near-finished script: (…)
config ipset
option name 'testlist' # ╭ Or "dst_net" but
option match 'src_net' # ←│ could it be just
option enabled '1' # ╰ directionless "net"?
list entry 2a00:86c0:2086::/48
list entry 45.57.40.0/23
list entry 2a00:86c0:2091::/48
list entry 2a00:86c0:2041::/48
list entry 45.57.86.0/24
list entry 2a00:86c0:2086::/47
list entry 2a00:86c0:2008::/48
list entry 45.57.8.0/24
list entry 2a00:86c0:2008::/47
list entry 45.57.8.0/23
list entry 45.57.40.0/24
list entry 2a00:86c0:2009::/48
list entry 45.57.41.0/24
list entry 2a00:86c0:2076::/47
…
list entry 45.57.76.0/23
To make it easier to maintain, I'd like it to output something like this: (…)
config ipset
option name 'testlist'
option match 'src_net'
option enabled '1'
option loadfile '/etc/config/something/file1'
option loadfile '/etc/config/something/file2'
# I haven't found a second line ⤴︎
# of these in the exemplified or
# mentioned in the OpenWRT docu yet
I can always concatenate the files, no biggie, except this way it would allow me to add some additional functionality I have in mind with very little no effort.
Will it work? Or will it error out or only take the first/last/one statement, undefined, etc? Any other tips/suggestions are also welcome, though maybe I should point out I'm not a dev, please keep it at an X-for-dummies level. =)
*/**
*: which I'll share when done. I already started documenting it.
**: meaning: in some big config file where they're stored, like /etc/config/firewall
or something similar. I haven't gotten to that part yet. Thanks