Skip to content

Commit

Permalink
ipsec: refactor security policies
Browse files Browse the repository at this point in the history
Signed-off-by: Milan Lenco <milan.lenco@pantheon.tech>
  • Loading branch information
Milan Lenco committed Jul 29, 2020
1 parent d9d463c commit e19dade
Show file tree
Hide file tree
Showing 40 changed files with 1,350 additions and 933 deletions.
4 changes: 4 additions & 0 deletions clientv2/linux/data_change_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ type PutDSL interface {
IPSecSA(sa *ipsec.SecurityAssociation) PutDSL
// IPSecSPD adds request to create a new Security Policy Database
IPSecSPD(spd *ipsec.SecurityPolicyDatabase) PutDSL
// IPSecSP adds request to create a new Security Policy
IPSecSP(sp *ipsec.SecurityPolicy) PutDSL
// IPSecTunnelProtection adds request to create a new IPSec tunnel protection
IPSecTunnelProtection(tp *ipsec.TunnelProtection) PutDSL
// PuntIPRedirect adds request to create or update rule to punt L3 traffic via interface.
Expand Down Expand Up @@ -207,6 +209,8 @@ type DeleteDSL interface {
IPSecSA(saIndex uint32) DeleteDSL
// IPSecSPD adds request to delete a Security Policy Database
IPSecSPD(spdIndex uint32) DeleteDSL
// IPSecSP adds request to delete a Security Policy
IPSecSP(sp *ipsec.SecurityPolicy) DeleteDSL
// IPSecTunnelProtection adds request to delete an IPSec tunnel protection from an interface
IPSecTunnelProtection(tp *ipsec.TunnelProtection) DeleteDSL
// PuntIPRedirect adds request to delete a rule used to punt L3 traffic via interface.
Expand Down
2 changes: 2 additions & 0 deletions clientv2/linux/data_resync_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ type DataResyncDSL interface {
IPSecSA(sa *ipsec.SecurityAssociation) DataResyncDSL
// IPSecSPD adds request to RESYNC a new Security Policy Database
IPSecSPD(spd *ipsec.SecurityPolicyDatabase) DataResyncDSL
// IPSecSP adds Security Policy to the RESYNC request
IPSecSP(sp *ipsec.SecurityPolicy) DataResyncDSL
// IPSecTunnelProtection adds request to RESYNC an IPSec tunnel protection
IPSecTunnelProtection(tp *ipsec.TunnelProtection) DataResyncDSL
// PuntIPRedirect adds request to RESYNC a rule used to punt L3 traffic via interface.
Expand Down
12 changes: 12 additions & 0 deletions clientv2/linux/dbadapter/data_change_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,12 @@ func (dsl *PutDSL) IPSecSPD(spd *ipsec.SecurityPolicyDatabase) linuxclient.PutDS
return dsl
}

// IPSecSP adds request to create a new Security Policy
func (dsl *PutDSL) IPSecSP(sp *ipsec.SecurityPolicy) linuxclient.PutDSL {
dsl.vppPut.IPSecSP(sp)
return dsl
}

// IPSecTunnelProtection adds request to delete an IPSec tunnel protection from an interface
func (dsl *PutDSL) IPSecTunnelProtection(tp *ipsec.TunnelProtection) linuxclient.PutDSL {
dsl.vppPut.IPSecTunnelProtection(tp)
Expand Down Expand Up @@ -477,6 +483,12 @@ func (dsl *DeleteDSL) IPSecSPD(spdIndex uint32) linuxclient.DeleteDSL {
return dsl
}

// IPSecSP adds request to delete a Security Policy
func (dsl *DeleteDSL) IPSecSP(sp *ipsec.SecurityPolicy) linuxclient.DeleteDSL {
dsl.vppDelete.IPSecSP(sp)
return dsl
}

// IPSecTunnelProtection adds request to delete an IPSec tunnel protection from an interface
func (dsl *DeleteDSL) IPSecTunnelProtection(tp *ipsec.TunnelProtection) linuxclient.DeleteDSL {
dsl.vppDelete.IPSecTunnelProtection(tp)
Expand Down
6 changes: 6 additions & 0 deletions clientv2/linux/dbadapter/data_resync_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ func (dsl *DataResyncDSL) IPSecSPD(spd *ipsec.SecurityPolicyDatabase) linuxclien
return dsl
}

// IPSecSPD adds Security Policy into the RESYNC request
func (dsl *DataResyncDSL) IPSecSP(sp *ipsec.SecurityPolicy) linuxclient.DataResyncDSL {
dsl.vppDataResync.IPSecSP(sp)
return dsl
}

// IPSecTunnelProtection adds request to RESYNC an IPSec tunnel protection
func (dsl *DataResyncDSL) IPSecTunnelProtection(tp *ipsec.TunnelProtection) linuxclient.DataResyncDSL {
dsl.vppDataResync.IPSecTunnelProtection(tp)
Expand Down
4 changes: 4 additions & 0 deletions clientv2/vpp/data_change_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ type PutDSL interface {
IPSecSA(sa *ipsec.SecurityAssociation) PutDSL
// IPSecSPD adds request to create a new Security Policy Database
IPSecSPD(spd *ipsec.SecurityPolicyDatabase) PutDSL
// IPSecSP adds request to add a new Security Policy
IPSecSP(sp *ipsec.SecurityPolicy) PutDSL
// IPSecTunnelProtection adds request to create a new IPSec tunnel protection
IPSecTunnelProtection(tp *ipsec.TunnelProtection) PutDSL
// PuntIPRedirect adds request to create or update rule to punt L3 traffic via interface.
Expand Down Expand Up @@ -157,6 +159,8 @@ type DeleteDSL interface {
IPSecSA(saIndex uint32) DeleteDSL
// IPSecSPD adds request to delete a Security Policy Database
IPSecSPD(spdIndex uint32) DeleteDSL
// IPSecSP adds request to delete a Security Policy
IPSecSP(sp *ipsec.SecurityPolicy) DeleteDSL
// IPSecTunnelProtection adds request to delete an IPSec tunnel protection from an interface
IPSecTunnelProtection(tp *ipsec.TunnelProtection) DeleteDSL
// PuntIPRedirect adds request to delete a rule used to punt L3 traffic via interface.
Expand Down
2 changes: 2 additions & 0 deletions clientv2/vpp/data_resync_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type DataResyncDSL interface {
IPSecSA(sa *ipsec.SecurityAssociation) DataResyncDSL
// IPSecSPD adds request to RESYNC a new Security Policy Database
IPSecSPD(spd *ipsec.SecurityPolicyDatabase) DataResyncDSL
// IPSecSP adds Security Policy to the RESYNC request
IPSecSP(sp *ipsec.SecurityPolicy) DataResyncDSL
// IPSecTunnelProtection adds request to RESYNC an IPSec tunnel protection
IPSecTunnelProtection(tp *ipsec.TunnelProtection) DataResyncDSL
// PuntIPRedirect adds request to RESYNC a rule used to punt L3 traffic via interface.
Expand Down
12 changes: 12 additions & 0 deletions clientv2/vpp/dbadapter/data_change_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ func (dsl *PutDSL) IPSecSPD(spd *ipsec.SecurityPolicyDatabase) vppclient.PutDSL
return dsl
}

// IPSecSP adds request to create a new Security Policy
func (dsl *PutDSL) IPSecSP(sp *ipsec.SecurityPolicy) vppclient.PutDSL {
dsl.parent.txn.Put(models.Key(sp), sp)
return dsl
}

// IPSecTunnelProtection adds request to delete an IPSec tunnel protection from an interface
func (dsl *PutDSL) IPSecTunnelProtection(tp *ipsec.TunnelProtection) vppclient.PutDSL {
dsl.parent.txn.Put(models.Key(tp), tp)
Expand Down Expand Up @@ -361,6 +367,12 @@ func (dsl *DeleteDSL) IPSecSPD(spdIndex uint32) vppclient.DeleteDSL {
return dsl
}

// IPSecSP adds request to delete Security Policy
func (dsl *DeleteDSL) IPSecSP(sp *ipsec.SecurityPolicy) vppclient.DeleteDSL {
dsl.parent.txn.Delete(models.Key(sp))
return dsl
}

// IPSecTunnelProtection adds request to delete an IPSec tunnel protection from an interface
func (dsl *DeleteDSL) IPSecTunnelProtection(tp *ipsec.TunnelProtection) vppclient.DeleteDSL {
dsl.parent.txn.Delete(models.Key(tp))
Expand Down
9 changes: 9 additions & 0 deletions clientv2/vpp/dbadapter/data_resync_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ func (dsl *DataResyncDSL) IPSecSPD(spd *ipsec.SecurityPolicyDatabase) vppclient.
return dsl
}

// IPSecSP adds request to RESYNC a Security Policy
func (dsl *DataResyncDSL) IPSecSP(sp *ipsec.SecurityPolicy) vppclient.DataResyncDSL {
key := models.Key(sp)
dsl.txn.Put(key, sp)
dsl.txnKeys = append(dsl.txnKeys, key)

return dsl
}

// IPSecTunnelProtection adds request to RESYNC an IPSec tunnel protection
func (dsl *DataResyncDSL) IPSecTunnelProtection(tp *ipsec.TunnelProtection) vppclient.DataResyncDSL {
key := models.Key(tp)
Expand Down
22 changes: 13 additions & 9 deletions examples/grpc_vpp/remote_client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (p *ExamplePlugin) demonstrateClient(client configurator.ConfiguratorServic
IpscanNeighbor: ipScanNeigh,
IpsecSas: []*vpp_ipsec.SecurityAssociation{sa10},
IpsecSpds: []*vpp_ipsec.SecurityPolicyDatabase{spd1},
IpsecSps: []*vpp_ipsec.SecurityPolicy{sp},
},
LinuxConfig: &linux.ConfigData{
Interfaces: []*linux_interfaces.Interface{
Expand Down Expand Up @@ -216,15 +217,18 @@ var (
}
spd1 = &vpp.IPSecSPD{
Index: 1,
PolicyEntries: []*vpp_ipsec.SecurityPolicyDatabase_PolicyEntry{
{
Action: vpp_ipsec.SecurityPolicyDatabase_PolicyEntry_BYPASS,
Priority: 100,
IsOutbound: false,
Protocol: 50,
SaIndex: 10,
},
},
}
sp = &vpp.IPSecSP{
SpdIndex: spd1.Index,
SaIndex: sa10.Index,
Action: vpp_ipsec.SecurityPolicy_BYPASS,
Priority: 100,
IsOutbound: false,
Protocol: 50,
LocalAddrStart: "192.168.1.1",
LocalAddrStop: "192.168.1.255",
RemoteAddrStart: "192.168.2.1",
RemoteAddrStop: "192.168.2.255",
}
memif1 = &vpp.Interface{
Name: "memif1",
Expand Down
22 changes: 15 additions & 7 deletions plugins/configurator/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ func (svc *dumpService) Dump(ctx context.Context, req *rpc.DumpRequest) (*rpc.Du
svc.log.Errorf("DumpIPSecSPDs failed: %v", err)
return nil, err
}
dump.VppConfig.IpsecSps, err = svc.DumpIPSecSPs()
if err != nil {
svc.log.Errorf("DumpIPSecSPs failed: %v", err)
return nil, err
}
dump.VppConfig.IpsecSas, err = svc.DumpIPSecSAs()
if err != nil {
svc.log.Errorf("DumpIPSecSAs failed: %v", err)
Expand Down Expand Up @@ -205,14 +210,17 @@ func (svc *dumpService) DumpIPSecSPDs() (spds []*vpp_ipsec.SecurityPolicyDatabas
return nil, nil
}

spdDetails, err := svc.ipsecHandler.DumpIPSecSPD()
if err != nil {
return nil, err
}
for _, spd := range spdDetails {
spds = append(spds, spd.Spd)
return svc.ipsecHandler.DumpIPSecSPD()
}

// DumpIPSecSPs dumps IPSec security policies.
func (svc *dumpService) DumpIPSecSPs() (spds []*vpp_ipsec.SecurityPolicy, err error) {
if svc.ipsecHandler == nil {
// handler is not available
return nil, nil
}
return spds, nil

return svc.ipsecHandler.DumpIPSecSP()
}

// DumpIPSecSAs reads IPSec SA and returns them as an *IPSecSAResponse. If reading ends up with error,
Expand Down
7 changes: 7 additions & 0 deletions plugins/restapi/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ func (p *Plugin) registerIPSecHandlers() {
}
return p.ipSecHandler.DumpIPSecSPD()
})
// GET IPSec SP entries
p.registerHTTPHandler(resturl.SPs, GET, func() (interface{}, error) {
if p.ipSecHandler == nil {
return nil, ErrHandlerUnavailable
}
return p.ipSecHandler.DumpIPSecSP()
})
// GET IPSec SA entries
p.registerHTTPHandler(resturl.SAs, GET, func() (interface{}, error) {
if p.ipSecHandler == nil {
Expand Down
2 changes: 2 additions & 0 deletions plugins/restapi/resturl/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ const (
const (
// SPDs is rest IPSec security policy database path
SPDs = "/dump/vpp/v2/ipsec/spds"
// SPs is rest IPSec security policy path
SPs = "/dump/vpp/v2/ipsec/sps"
// SAs is rest IPSec security association path
SAs = "/dump/vpp/v2/ipsec/sas"
)
Expand Down
Loading

0 comments on commit e19dade

Please sign in to comment.