add missing error-catching

refs #5
This commit is contained in:
Leo Antunes 2019-07-29 19:20:25 +02:00
parent 2edf641c46
commit c6e052c78f
1 changed files with 15 additions and 6 deletions

View File

@ -85,22 +85,31 @@ func (wg *wgState) setUpInterface(nodes []node) error {
if err != nil { if err != nil {
return errors.Wrap(err, "error converting received node information to wireguard format") return errors.Wrap(err, "error converting received node information to wireguard format")
} }
wg.client.ConfigureDevice(wg.iface, wgtypes.Config{ if err := wg.client.ConfigureDevice(wg.iface, wgtypes.Config{
PrivateKey: &wg.PrivKey, PrivateKey: &wg.PrivKey,
ListenPort: &wg.Port, ListenPort: &wg.Port,
ReplacePeers: true, ReplacePeers: true,
Peers: peerCfgs, Peers: peerCfgs,
}) }); err != nil {
return errors.Wrapf(err, "could not set wireguard configuration for %s", wg.iface)
}
link, err := netlink.LinkByName(wg.iface) link, err := netlink.LinkByName(wg.iface)
if err != nil { if err != nil {
return errors.Wrapf(err, "could not get link information for %s", wg.iface) return errors.Wrapf(err, "could not get link information for %s", wg.iface)
} }
netlink.AddrReplace(link, &netlink.Addr{ if err := netlink.AddrReplace(link, &netlink.Addr{
IPNet: &wg.OverlayAddr, IPNet: &wg.OverlayAddr,
}) }); err != nil {
netlink.LinkSetMTU(link, 1420) // TODO: make MTU configurable? return errors.Wrapf(err, "could not set address for %s", wg.iface)
netlink.LinkSetUp(link) }
// TODO: make MTU configurable?
if err := netlink.LinkSetMTU(link, 1420); err != nil {
return errors.Wrapf(err, "could not set MTU for %s", wg.iface)
}
if err := netlink.LinkSetUp(link); err != nil {
return errors.Wrapf(err, "could not enable interface %s", wg.iface)
}
for _, node := range nodes { for _, node := range nodes {
netlink.RouteAdd(&netlink.Route{ netlink.RouteAdd(&netlink.Route{
LinkIndex: link.Attrs().Index, LinkIndex: link.Attrs().Index,