I'm starting to use the Strongswan govici
API to control IPsec, following the general pattern I found at https://github.com/strongswan/govici/blob/master/docs/getting_started.md.
It's working except that I'm unable to set a connection's childSA's map_in
and map_out
fields.
package main
import (
"fmt"
"github.com/k0kubun/pp/v3"
"github.com/strongswan/govici/vici"
)
func main() {
type childSA struct {
markIn string `vici:"mark_in"`
markOut string `vici:"mark_out"`
}
type viciConnection struct {
LocalAddrs []string `vici:"local_addrs"`
RemoteAddrs []string `vici:"remote_addrs"`
Children map[string]*childSA `vici:"children"`
}
vc := viciConnection{
LocalAddrs: []string{"1.1.1.1"},
RemoteAddrs: []string{"2.2.2.2"},
Children: map[string]*childSA{
"onlyChild": &childSA{
markIn: "4/0xffffffff",
markOut: "4",
},
},
}
c, err := vici.MarshalMessage(vc)
if err != nil {
fmt.Printf("%v\n", err)
return
}
pp.Default.SetColoringEnabled(false)
fmt.Printf("Marshalled message: %s\n", pp.Sprint(c))
}
Output:
Marshalled message: &vici.Message{
keys: []string{
"local_addrs",
"remote_addrs",
"children",
},
data: map[string]interface {}{
"children": &vici.Message{
keys: []string{
"onlyChild",
},
data: map[string]interface {}{
"onlyChild": &vici.Message{
keys: []string{},
data: map[string]interface {}{},
},
},
},
"local_addrs": []string{
"1.1.1.1",
},
"remote_addrs": []string{
"2.2.2.2",
},
},
}
Under onlyChild
I expect to see mark_in
and mark_out
fields, in the keys
and data
sections, but they're missing.
Run it here: https://goplay.tools/snippet/WRoelsjbf9M
Thanks to @BurakSerdar: capitalize the field names so that they're exported fields: