From e9561379c439d1472b51bf5efee3d76b8d373208 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Fri, 31 Jan 2025 13:28:21 +0100 Subject: [PATCH] Fix `GET /rules/` REST API returning error; close #117 --- internal/database/database.go | 55 +++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 25 deletions(-) diff --git a/internal/database/database.go b/internal/database/database.go index 7e7cc55..b9a9241 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -211,23 +211,25 @@ func (db *Database) GetRule(ctx context.Context, uuid uuid.UUID) (n4tosrv6.Rule, } if action_source_gtp4 == nil { - return n4tosrv6.Rule{}, fmt.Errorf("Empty SourceGtp4 for downlink rule") - } + rule.Action = n4tosrv6.Action{ + SRH: *srh, + SourceGtp4: nil, + } + } else { - source_gtp4, err := netip.ParseAddr(*action_source_gtp4) - if err != nil { - return n4tosrv6.Rule{}, err - } + source_gtp4, err := netip.ParseAddr(*action_source_gtp4) + if err != nil { + return n4tosrv6.Rule{}, err + } - rule.Action = n4tosrv6.Action{ - SRH: *srh, - SourceGtp4: &source_gtp4, + rule.Action = n4tosrv6.Action{ + SRH: *srh, + SourceGtp4: &source_gtp4, + } } - return rule, err - } else { - return n4tosrv6.Rule{}, fmt.Errorf("Procedure not registered") } + return n4tosrv6.Rule{}, fmt.Errorf("Procedure not registered") } func (db *Database) GetRules(ctx context.Context) (n4tosrv6.RuleMap, error) { @@ -304,32 +306,35 @@ func (db *Database) GetRules(ctx context.Context) (n4tosrv6.RuleMap, error) { } } } - if action_source_gtp4 == nil { - return n4tosrv6.RuleMap{}, fmt.Errorf("Empty SourceGtp4 for downlink rule") - } - - source_gtp4, err := netip.ParseAddr(*action_source_gtp4) - if err != nil { - return n4tosrv6.RuleMap{}, err - } srh, err := n4tosrv6.NewSRH(action_srh) if err != nil { return n4tosrv6.RuleMap{}, err } - rule.Action = n4tosrv6.Action{ - SRH: *srh, - SourceGtp4: &source_gtp4, + if action_source_gtp4 == nil { + rule.Action = n4tosrv6.Action{ + SRH: *srh, + SourceGtp4: nil, + } + } else { + source_gtp4, err := netip.ParseAddr(*action_source_gtp4) + if err != nil { + return n4tosrv6.RuleMap{}, err + } + + rule.Action = n4tosrv6.Action{ + SRH: *srh, + SourceGtp4: &source_gtp4, + } } m[uuid] = rule } } return m, nil - } else { - return n4tosrv6.RuleMap{}, fmt.Errorf("Procedure not registered") } + return n4tosrv6.RuleMap{}, fmt.Errorf("Procedure not registered") } func (db *Database) EnableRule(ctx context.Context, uuid uuid.UUID) error {