I'm writing an Internet management system in Go, replacing and greatly
improving on the current system written in Lua. Lua rocks in its own
right, but this project's future is Go.
In the Lua code I avoided system calls, and instead parsed or edited proc
files or executed external commands to do the work for me. In the new Go
version, I could take the same tack, but I feel I would be missing an
opportunity. I'm hoping an experienced Linux dev would be able to offer
some useful advice.
I'm looking for some suggestions for accomplishing the following:
1) Obtaining a device's hardware address from IP
In Lua, I currently parse /proc/net/arp. Bit of googling indicates that I
want to call SIOCGARP, which go lists
in http://golang.org/pkg/syscall/#pkg-constants as an untyped constant.
But there's a stack of different functions listed in syscall, I'm not sure
what to use, or how to use it. Can anyone provide a simple example?
Ideally it would be nice to use higher level packages such as net, but it
only seems to expose hardware addresses of local interfaces...(which is
useful, just not for this problem).
2) Enable packet forwarding.
In Lua I write 1 to /proc/sys/net/ipv4/ip_forward, which works but, anyone
suggest a better way?
3) Create a new interface, or alter an existing one.
In Lua I run ifconfig eth0:1 <ip>
4) Set nameservers.
In Lua I rewrite /etc/resolv.conf. Is there a better way?
5) Configure firewall
In Lua I call /sbin/iptables. I have doubts as to whether it would be a
good idea to attempt this using syscalls. But if I could pull it off in a
sane way, it would probably help with reading back counters, which I
currently do by regexp matching the output of iptables -L.
I've probably asked way too much in one message, so any tips on any of the
above would be appreciated.
Cheers.
--