@@ -125,7 +125,14 @@ func (db *Database) InsertRule(ctx context.Context, r n4tosrv6.Rule) (*uuid.UUID
125125 } else {
126126 dst = r .Match .Payload .Dst .String () + "/32"
127127 }
128- err := stmt .QueryRowContext (ctx , r .Enabled , dst , pq .Array (srh )).Scan (& id )
128+ src_ipv6 := "::"
129+ if r .Action .SourceGtp4 != nil {
130+ src_ipv6 = r .Action .SourceGtp4 .String ()
131+ } else {
132+ return nil , fmt .Errorf ("Empty SourceGtp4 for downlink Action" )
133+ }
134+
135+ err := stmt .QueryRowContext (ctx , r .Enabled , dst , pq .Array (srh ), src_ipv6 ).Scan (& id )
129136 return & id , err
130137 } else {
131138 return nil , fmt .Errorf ("Procedure not registered" )
@@ -139,13 +146,14 @@ func (db *Database) GetRule(ctx context.Context, uuid uuid.UUID) (n4tosrv6.Rule,
139146 var type_uplink bool
140147 var enabled bool
141148 var action_srh []string
149+ var action_source_gtp4 * string
142150 var match_ue_ip string
143151 var match_gnb_ip []string
144152 var match_service_ip * string
145153 var match_uplink_teid * uint32
146154 var match_uplink_upf * string
147155 if stmt , ok := db .stmt ["get_rule" ]; ok {
148- err := stmt .QueryRowContext (ctx , uuid .String ()).Scan (& type_uplink , & enabled , pq .Array (& action_srh ), & match_ue_ip , pq .Array (& match_gnb_ip ), & match_uplink_teid , & match_uplink_upf , & match_service_ip )
156+ err := stmt .QueryRowContext (ctx , uuid .String ()).Scan (& type_uplink , & enabled , pq .Array (& action_srh ), & action_source_gtp4 , & match_ue_ip , pq .Array (& match_gnb_ip ), & match_uplink_teid , & match_uplink_upf , & match_service_ip )
149157 if err != nil {
150158 return n4tosrv6.Rule {}, err
151159 }
@@ -202,8 +210,18 @@ func (db *Database) GetRule(ctx context.Context, uuid uuid.UUID) (n4tosrv6.Rule,
202210 return n4tosrv6.Rule {}, err
203211 }
204212
213+ if action_source_gtp4 == nil {
214+ return n4tosrv6.Rule {}, fmt .Errorf ("Empty SourceGtp4 for downlink rule" )
215+ }
216+
217+ source_gtp4 , err := netip .ParseAddr (* action_source_gtp4 )
218+ if err != nil {
219+ return n4tosrv6.Rule {}, err
220+ }
221+
205222 rule .Action = n4tosrv6.Action {
206- SRH : * srh ,
223+ SRH : * srh ,
224+ SourceGtp4 : & source_gtp4 ,
207225 }
208226
209227 return rule , err
@@ -217,6 +235,7 @@ func (db *Database) GetRules(ctx context.Context) (n4tosrv6.RuleMap, error) {
217235 var type_uplink bool
218236 var enabled bool
219237 var action_srh []string
238+ var action_source_gtp4 * string
220239 var match_ue_ip string
221240 var match_gnb_ip []string
222241 var match_uplink_teid * uint32
@@ -234,7 +253,7 @@ func (db *Database) GetRules(ctx context.Context) (n4tosrv6.RuleMap, error) {
234253 // avoid looping if no longer necessary
235254 return n4tosrv6.RuleMap {}, ctx .Err ()
236255 default :
237- err := rows .Scan (& uuid , & type_uplink , & enabled , pq .Array (& action_srh ), & match_ue_ip , pq .Array (& match_gnb_ip ), & match_uplink_teid , & match_uplink_upf , & match_service_ip )
256+ err := rows .Scan (& uuid , & type_uplink , & enabled , pq .Array (& action_srh ), & action_source_gtp4 , & match_ue_ip , pq .Array (& match_gnb_ip ), & match_uplink_teid , & match_uplink_upf , & match_service_ip )
238257 if err != nil {
239258 return m , err
240259 }
@@ -285,14 +304,23 @@ func (db *Database) GetRules(ctx context.Context) (n4tosrv6.RuleMap, error) {
285304 }
286305 }
287306 }
307+ if action_source_gtp4 == nil {
308+ return n4tosrv6.RuleMap {}, fmt .Errorf ("Empty SourceGtp4 for downlink rule" )
309+ }
310+
311+ source_gtp4 , err := netip .ParseAddr (* action_source_gtp4 )
312+ if err != nil {
313+ return n4tosrv6.RuleMap {}, err
314+ }
288315
289316 srh , err := n4tosrv6 .NewSRH (action_srh )
290317 if err != nil {
291318 return n4tosrv6.RuleMap {}, err
292319 }
293320
294321 rule .Action = n4tosrv6.Action {
295- SRH : * srh ,
322+ SRH : * srh ,
323+ SourceGtp4 : & source_gtp4 ,
296324 }
297325 m [uuid ] = rule
298326 }
@@ -351,36 +379,55 @@ func (db *Database) GetUplinkAction(ctx context.Context, uplinkFTeid jsonapi.Fte
351379 if err != nil {
352380 return n4tosrv6.Action {}, err
353381 }
354- return n4tosrv6.Action {SRH : * srh }, err
382+ return n4tosrv6.Action {
383+ SRH : * srh ,
384+ }, err
355385 } else {
356386 return n4tosrv6.Action {}, fmt .Errorf ("Procedure not registered" )
357387 }
358388}
359389
360390func (db * Database ) GetDownlinkAction (ctx context.Context , ueIp netip.Addr ) (n4tosrv6.Action , error ) {
361391 var action_srh []string
392+ var action_source_gtp4 * string
362393 if stmt , ok := db .stmt ["get_downlink_action" ]; ok {
363- err := stmt .QueryRowContext (ctx , ueIp .String ()).Scan (pq .Array (& action_srh ))
394+ err := stmt .QueryRowContext (ctx , ueIp .String ()).Scan (pq .Array (& action_srh ), & action_source_gtp4 )
364395 if err != nil {
365396 return n4tosrv6.Action {}, err
366397 }
367398 srh , err := n4tosrv6 .NewSRH (action_srh )
368399 if err != nil {
369400 return n4tosrv6.Action {}, err
370401 }
371- return n4tosrv6.Action {SRH : * srh }, err
402+ if action_source_gtp4 == nil {
403+ return n4tosrv6.Action {}, fmt .Errorf ("Empty SourceGtp4 for downlink rule" )
404+ }
405+ source_gtp4 , err := netip .ParseAddr (* action_source_gtp4 )
406+ if err != nil {
407+ return n4tosrv6.Action {}, err
408+ }
409+ return n4tosrv6.Action {
410+ SRH : * srh ,
411+ SourceGtp4 : & source_gtp4 ,
412+ }, err
372413 } else {
373414 return n4tosrv6.Action {}, fmt .Errorf ("Procedure not registered" )
374415 }
375416}
376417
377418func (db * Database ) UpdateAction (ctx context.Context , uuidRule uuid.UUID , action n4tosrv6.Action ) error {
378419 srh := []string {}
420+ source_gtp4 := "::"
421+ if action .SourceGtp4 != nil {
422+ source_gtp4 = action .SourceGtp4 .String ()
423+ } else {
424+ return fmt .Errorf ("Empty SourceGtp4 for downlink rule" )
425+ }
379426 for _ , ip := range action .SRH {
380427 srh = append (srh , ip .String ())
381428 }
382429 if stmt , ok := db .stmt ["update_action" ]; ok {
383- _ , err := stmt .ExecContext (ctx , uuidRule .String (), pq .Array (srh ))
430+ _ , err := stmt .ExecContext (ctx , uuidRule .String (), pq .Array (srh ), source_gtp4 )
384431 return err
385432 } else {
386433 return fmt .Errorf ("Procedure not registered" )
0 commit comments