-
Notifications
You must be signed in to change notification settings - Fork 51
/
datapath_udp.go
640 lines (532 loc) · 21.4 KB
/
datapath_udp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
package nfqdatapath
// Go libraries
import (
"errors"
"fmt"
"net"
"strconv"
"strings"
"go.uber.org/zap"
"go.aporeto.io/trireme-lib/collector"
"go.aporeto.io/trireme-lib/controller/constants"
"go.aporeto.io/trireme-lib/controller/internal/enforcer/constants"
"go.aporeto.io/trireme-lib/controller/pkg/connection"
"go.aporeto.io/trireme-lib/controller/pkg/packet"
"go.aporeto.io/trireme-lib/controller/pkg/pucontext"
"go.aporeto.io/trireme-lib/controller/pkg/tokens"
)
// ProcessNetworkUDPPacket processes packets arriving from network and are destined to the application
func (d *Datapath) ProcessNetworkUDPPacket(p *packet.Packet) (err error) {
if d.packetLogs {
zap.L().Debug("Processing network packet ",
zap.String("flow", p.L4FlowHash()),
)
defer zap.L().Debug("Finished Processing network packet ",
zap.String("flow", p.L4FlowHash()),
zap.Error(err),
)
}
var conn *connection.UDPConnection
udpPacketType := p.GetUDPType()
zap.L().Debug("Got packet of type:", zap.Reflect("Type", udpPacketType), zap.Reflect("Len", len(p.Buffer)))
switch udpPacketType {
case packet.UDPSynMask:
zap.L().Debug("Received Syn Network packet")
conn, err = d.netSynUDPRetrieveState(p)
if err != nil {
if d.packetLogs {
zap.L().Debug("Packet rejected",
zap.String("flow", p.L4FlowHash()),
zap.Error(err),
)
}
return err
}
if conn == nil {
zap.L().Debug("Conn should never be nil")
return fmt.Errorf("Unable to create new connection")
}
conn.SetState(connection.UDPSynReceived)
case packet.UDPSynAckMask:
zap.L().Debug("Received Syn Ack Network packet")
conn, err = d.netSynAckUDPRetrieveState(p)
if err != nil {
if d.packetLogs {
zap.L().Debug("Syn ack Packet Rejected/ignored",
zap.String("flow", p.L4FlowHash()),
)
}
// flush the packetQueue on errors.
if conn != nil {
zap.L().Debug("Dropping packets ")
conn.DropPackets()
}
return err
}
case packet.UDPAckMask:
zap.L().Debug("Received udp Network packet")
conn, err = d.netUDPAckRetrieveState(p)
if err != nil {
if d.packetLogs {
zap.L().Debug("Packet rejected",
zap.String("flow", p.L4FlowHash()),
zap.Error(err),
)
}
return err
}
default:
// Decrypt the packet and deliver to the application.
zap.L().Debug("Not an aporeto handshake packet, Check for encryption", zap.String("flow", p.L4FlowHash()))
conn, err = d.netUDPAckRetrieveState(p)
if err != nil {
if d.packetLogs {
zap.L().Debug("No connection found for the flow, Dropping it",
zap.String("flow", p.L4FlowHash()),
zap.Error(err),
)
}
return err
}
// decrypt the packet
if d.service != nil {
if !d.service.PostProcessUDPNetPacket(p, nil, nil, conn.Context, conn) {
p.Print(packet.PacketFailureService)
return errors.New("post service processing failed for network packet")
}
}
zap.L().Debug("Delivering packet to application")
return nil
}
p.Print(packet.PacketStageIncoming)
if d.service != nil {
if !d.service.PreProcessUDPNetPacket(p, conn.Context, conn) {
p.Print(packet.PacketFailureService)
return errors.New("pre service processing failed for network packet")
}
}
// handle handshake packets and do not deliver to application.
err = d.processNetUDPPacket(p, conn.Context, conn)
if err != nil {
if d.packetLogs {
zap.L().Debug("Rejecting packet ",
zap.String("flow", p.L4FlowHash()),
zap.Error(err),
)
}
return fmt.Errorf("packet processing failed for network packet: %s", err)
}
// handshake packets are not to be delivered to application.
return fmt.Errorf("Drop net hanshake packets (udp)")
}
func (d *Datapath) netSynUDPRetrieveState(p *packet.Packet) (*connection.UDPConnection, error) {
context, err := d.contextFromIP(false, p.DestinationAddress.String(), p.Mark, p.DestinationPort, packet.IPProtocolUDP)
if err != nil {
zap.L().Debug("Received Packets from unenforcerd process")
return nil, err
}
return connection.NewUDPConnection(context, d.udpSocketWriter), nil
}
func (d *Datapath) netSynAckUDPRetrieveState(p *packet.Packet) (*connection.UDPConnection, error) {
conn, err := d.udpSourcePortConnectionCache.GetReset(p.SourcePortHash(packet.PacketTypeNetwork), 0)
if err != nil {
if d.packetLogs {
zap.L().Debug("No connection for udp SynAck packet, ignore it",
zap.String("flow", p.L4FlowHash()),
)
}
// ignore the syn ack packet.
return nil, nil
}
return conn.(*connection.UDPConnection), nil
}
func (d *Datapath) netUDPAckRetrieveState(p *packet.Packet) (*connection.UDPConnection, error) {
hash := p.L4FlowHash()
conn, err := d.udpNetReplyConnectionTracker.GetReset(hash, 0)
if err != nil {
conn, err = d.udpNetOrigConnectionTracker.GetReset(hash, 0)
if err != nil {
return nil, fmt.Errorf("net state not found: %s", err)
}
}
return conn.(*connection.UDPConnection), nil
}
// processNetUDPPacket processes a network UDP packet and dispatches it to different methods based on the flags
func (d *Datapath) processNetUDPPacket(udpPacket *packet.Packet, context *pucontext.PUContext, conn *connection.UDPConnection) (err error) {
if conn == nil {
return nil
}
udpPacketType := udpPacket.GetUDPType()
// Update connection state in the internal state machine tracker
switch udpPacketType {
case packet.UDPSynMask:
zap.L().Debug("Prcessing net udp syn packet")
action, claims, err := d.processNetworkUDPSynPacket(context, conn, udpPacket)
if err != nil {
return err
}
if d.service != nil {
if !d.service.PostProcessUDPNetPacket(udpPacket, action, claims, conn.Context, conn) {
udpPacket.Print(packet.PacketFailureService)
return errors.New("post service processing failed for network packet")
}
}
// setup Encryption based on action and claims.
zap.L().Debug("Sending UDP syn ack packet")
err = d.sendUDPSynAckPacket(udpPacket, context, conn)
if err != nil {
return err
}
case packet.UDPAckMask:
zap.L().Debug("Processing network Ack Packet")
action, claims, err := d.processNetworkUDPAckPacket(udpPacket, context, conn)
if err != nil {
zap.L().Error("Error during authorization", zap.Error(err))
return err
}
// ack is processed, mark connmark rule and let other packets go through.
if d.service != nil {
if !d.service.PostProcessUDPNetPacket(udpPacket, action, claims, conn.Context, conn) {
udpPacket.Print(packet.PacketFailureService)
return errors.New("post service processing failed for network packet")
}
}
conn.SetState(connection.UDPAckProcessed)
// we have drop the handshake packet after succesfull completion of the handshake.
return fmt.Errorf("Drop udp ack (net) handshake packet as it is not intended for the application")
case packet.UDPSynAckMask:
// action, claims
zap.L().Debug("Processing net udp syn ack packet")
action, claims, err := d.processNetworkUDPSynAckPacket(udpPacket, context, conn)
if err != nil {
zap.L().Error("UDP Syn ack failed with", zap.Error(err))
return err
}
if d.service != nil {
if !d.service.PostProcessUDPNetPacket(udpPacket, action, claims, conn.Context, conn) {
udpPacket.Print(packet.PacketFailureService)
return errors.New("post service processing failed for network packet")
}
}
zap.L().Debug("Sending udp ack packet - 3rd packet")
err = d.sendUDPAckPacket(udpPacket, context, conn)
if err != nil {
zap.L().Error("Unable to send udp Syn ack failed", zap.Error(err))
return err
}
}
return nil
}
// ProcessApplicationUDPPacket processes packets arriving from an application and are destined to the network
func (d *Datapath) ProcessApplicationUDPPacket(p *packet.Packet) (err error) {
if d.packetLogs {
zap.L().Debug("Processing application UDP packet ",
zap.String("flow", p.L4FlowHash()),
)
defer zap.L().Debug("Finished Processing UDP application packet ",
zap.String("flow", p.L4FlowHash()),
zap.Error(err),
)
}
var conn *connection.UDPConnection
conn, err = d.appUDPRetrieveState(p)
if err != nil {
zap.L().Debug("Connection not found ?", zap.Error(err))
return fmt.Errorf("Received packet from unenforced process: %s", err)
}
// queue packets if connection is still unauthorized.
if conn.GetState() != connection.UDPAckProcessed {
zap.L().Debug("Packets are being queueed", zap.String("flow", p.L4FlowHash()))
if err = conn.QueuePackets(p); err != nil {
return fmt.Errorf("Unable to queue packets:%s", err)
}
}
switch conn.GetState() {
case connection.UDPSynStart:
// connection not authorized yet. queue the packets and start handshake.
zap.L().Debug("Sending out Application UDP Syn Packet with options", zap.String("flow", p.L4FlowHash()))
err = d.processApplicationUDPSynPacket(p, conn.Context, conn)
if err != nil {
return fmt.Errorf("Unable to send UDP Syn packet: %s", err)
}
case connection.UDPAckProcessed:
// check for encryption and do the needful.
if d.service != nil {
// PostProcessServiceInterface
if !d.service.PostProcessUDPAppPacket(p, nil, conn.Context, conn) {
p.Print(packet.PacketFailureService)
return errors.New("Encryption failed for application packet")
}
}
// Set verdict to 1.
zap.L().Debug("Ack Processed, write on the app socket")
return nil
}
// if not in the above two states, packets are queued. NFQ can drop them, as they are already
// in connection packet queue.
zap.L().Debug("Dropping packet by setting verdict to 0", zap.String("flow", p.L4FlowHash()))
return fmt.Errorf("Packets cloned. Dropping the original packet")
}
func (d *Datapath) appUDPRetrieveState(p *packet.Packet) (*connection.UDPConnection, error) {
hash := p.L4FlowHash()
if conn, err := d.udpAppReplyConnectionTracker.GetReset(hash, 0); err == nil {
return conn.(*connection.UDPConnection), nil
}
if conn, err := d.udpAppOrigConnectionTracker.GetReset(hash, 0); err == nil {
return conn.(*connection.UDPConnection), nil
}
context, err := d.contextFromIP(true, p.SourceAddress.String(), p.Mark, p.SourcePort, packet.IPProtocolUDP)
if err != nil {
return nil, errors.New("No context in app processing")
}
return connection.NewUDPConnection(context, d.udpSocketWriter), nil
}
// processApplicationUDPSynPacket processes a single Syn Packet
func (d *Datapath) processApplicationUDPSynPacket(udpPacket *packet.Packet, context *pucontext.PUContext, conn *connection.UDPConnection) (err error) {
// do some pre processing.
if d.service != nil {
// PreProcessServiceInterface
if !d.service.PreProcessUDPAppPacket(udpPacket, conn.Context, conn, packet.UDPSynMask) {
udpPacket.Print(packet.PacketFailureService)
return errors.New("pre service processing failed for UDP application packet")
}
}
udpOptions := d.CreateUDPAuthMarker(packet.UDPSynMask)
udpData, err := d.tokenAccessor.CreateSynPacketToken(context, &conn.Auth)
if err != nil {
return err
}
newPacket, err := d.clonePacketHeaders(udpPacket)
if err != nil {
return fmt.Errorf("Unable to clone packet: %s", err)
}
// Attach the UDP data and token
newPacket.UDPTokenAttach(udpOptions, udpData)
// send packet
err = d.udpSocketWriter.WriteSocket(newPacket.Buffer)
if err != nil {
zap.L().Debug("Unable to send syn token on raw socket", zap.Error(err))
}
// Set the state indicating that we send out a Syn packet
conn.SetState(connection.UDPSynSend)
// Poplate the caches to track the connection
hash := udpPacket.L4FlowHash()
d.udpAppOrigConnectionTracker.AddOrUpdate(hash, conn)
d.udpSourcePortConnectionCache.AddOrUpdate(newPacket.SourcePortHash(packet.PacketTypeApplication), conn)
d.udpNatConnectionTracker.AddOrUpdate(newPacket.SourcePortHash(packet.PacketTypeApplication), newPacket.SourcePortHash(packet.PacketTypeNetwork))
// Attach the tags to the packet and accept the packet
if d.service != nil {
// PostProcessServiceInterface
if !d.service.PostProcessUDPAppPacket(newPacket, nil, conn.Context, conn) {
newPacket.Print(packet.PacketFailureService)
return errors.New("post service processing failed for application packet")
}
}
return nil
}
func (d *Datapath) clonePacketHeaders(p *packet.Packet) (*packet.Packet, error) {
// copy the ip and udp headers.
newPacket := make([]byte, packet.UDPDataPos)
p.FixupIPHdrOnDataModify(p.IPTotalLength, packet.UDPDataPos)
_ = copy(newPacket, p.Buffer[:packet.UDPDataPos])
return packet.New(packet.PacketTypeApplication, newPacket, p.Mark)
}
// CreateUDPAuthMarker creates a UDP auth marker.
func (d *Datapath) CreateUDPAuthMarker(packetType uint8) []byte {
// Every UDP control packet has a 20 byte packet signature. The
// first 2 bytes represent the following control information.
// Byte 0 : Bits 0,1 are reserved fields.
// Bits 2,3,4 represent version information.
// Bits 5, 6 represent udp packet type,
// Bit 7 represents encryption. (currently unused).
// Byte 1: reserved for future use.
// Bytes [2:20]: Packet signature.
marker := make([]byte, packet.UDPSignatureLen)
// ignore version info as of now.
marker[0] |= packetType // byte 0
marker[1] = 0 // byte 1
// byte 2 - 19
copy(marker[2:], []byte(packet.UDPAuthMarker))
return marker
}
// processApplicationSynAckPacket processes a UDP SynAck packet
func (d *Datapath) sendUDPSynAckPacket(udpPacket *packet.Packet, context *pucontext.PUContext, conn *connection.UDPConnection) (err error) {
// check for service and configure encryption based on
// policy that was resolved on network syn.
if d.service != nil {
// PreProcessServiceInterface
if !d.service.PreProcessUDPAppPacket(udpPacket, context, conn, packet.UDPSynAckMask) {
udpPacket.Print(packet.PacketFailureService)
return errors.New("pre service processing failed for application packet")
}
}
// Create UDP Option
udpOptions := d.CreateUDPAuthMarker(packet.UDPSynAckMask)
udpData, err := d.tokenAccessor.CreateSynAckPacketToken(context, &conn.Auth)
if err != nil {
return err
}
udpPacket.CreateReverseFlowPacket(udpPacket.SourceAddress, udpPacket.SourcePort)
// Set the state for future reference
conn.SetState(connection.UDPSynAckSent)
// Attach the UDP data and token
udpPacket.UDPTokenAttach(udpOptions, udpData)
// Setup ConnMark for encryption.
if d.service != nil {
// PostProcessServiceInterface
if !d.service.PostProcessUDPAppPacket(udpPacket, nil, context, conn) {
udpPacket.Print(packet.PacketFailureService)
return errors.New("post service processing failed for application packet")
}
}
// send packet
err = d.udpSocketWriter.WriteSocket(udpPacket.Buffer)
if err != nil {
zap.L().Debug("Unable to send synack token on raw socket", zap.Error(err))
}
return nil
}
func (d *Datapath) sendUDPAckPacket(udpPacket *packet.Packet, context *pucontext.PUContext, conn *connection.UDPConnection) (err error) {
// Create UDP Option
zap.L().Debug("Sending UDP Ack packet", zap.String("flow", udpPacket.L4ReverseFlowHash()))
udpOptions := d.CreateUDPAuthMarker(packet.UDPAckMask)
udpData, err := d.tokenAccessor.CreateAckPacketToken(context, &conn.Auth)
if err != nil {
return err
}
srcPortHash, err := d.udpNatConnectionTracker.GetReset(udpPacket.SourcePortHash(packet.PacketTypeNetwork), 0)
if err != nil {
return fmt.Errorf("error getting actual destination")
}
destIPPort := srcPortHash.(string)
destIP := strings.Split(destIPPort, ":")[0]
destPort, err := (strconv.Atoi(strings.Split(destIPPort, ":")[1]))
if err != nil {
return fmt.Errorf("Unable to get dest port from cache")
}
udpPacket.CreateReverseFlowPacket(net.ParseIP(destIP), uint16(destPort))
// Attach the UDP data and token
udpPacket.UDPTokenAttach(udpOptions, udpData)
// send packet
err = d.udpSocketWriter.WriteSocket(udpPacket.Buffer)
if err != nil {
zap.L().Debug("Unable to send ack token on raw socket", zap.Error(err))
}
conn.SetState(connection.UDPAckProcessed)
if !conn.ServiceConnection {
zap.L().Debug("Plumbing the conntrack (app) rule for flow", zap.String("flow", udpPacket.L4FlowHash()))
if err = d.conntrackHdl.ConntrackTableUpdateMark(
destIP,
udpPacket.SourceAddress.String(),
udpPacket.IPProto,
uint16(destPort),
udpPacket.SourcePort,
constants.DefaultConnMark,
); err != nil {
zap.L().Error("Failed to update conntrack table for flow",
zap.String("context", string(conn.Auth.LocalContext)),
zap.String("app-conn", udpPacket.L4ReverseFlowHash()),
zap.String("state", fmt.Sprintf("%d", conn.GetState())),
zap.Error(err),
)
}
}
// Transmit Queued Packets.
for _, udpPacket := range conn.PacketQueue {
// check for Encryption.
if d.service != nil {
// PostProcessServiceInterface
if !d.service.PostProcessUDPAppPacket(udpPacket, nil, conn.Context, conn) {
udpPacket.Print(packet.PacketFailureService)
return errors.New("Encryption failed for queued application packet")
}
}
zap.L().Debug("Transmitting Queued UDP packets")
err = d.udpSocketWriter.WriteSocket(udpPacket.Buffer)
if err != nil {
zap.L().Error("Unable to transmit Queued UDP packets", zap.Error(err))
}
}
return err
}
// processNetworkUDPSynPacket processes a syn packet arriving from the network
func (d *Datapath) processNetworkUDPSynPacket(context *pucontext.PUContext, conn *connection.UDPConnection, udpPacket *packet.Packet) (action interface{}, claims *tokens.ConnectionClaims, err error) {
// what about external services ??????
claims, err = d.tokenAccessor.ParsePacketToken(&conn.Auth, udpPacket.ReadUDPToken())
if err != nil {
d.reportUDPRejectedFlow(udpPacket, conn, collector.DefaultEndPoint, context.ManagementID(), context, collector.InvalidToken, nil, nil)
return nil, nil, fmt.Errorf("UDP Syn packet dropped because of invalid token: %s", err)
}
// if there are no claims we must drop the connection and we drop the Syn
// packet. The source will retry but we have no state to maintain here.
if claims == nil {
d.reportUDPRejectedFlow(udpPacket, conn, collector.DefaultEndPoint, context.ManagementID(), context, collector.InvalidToken, nil, nil)
return nil, nil, errors.New("UDP Syn packet dropped because of no claims")
}
// Why is this required. Take a look.
txLabel, _ := claims.T.Get(enforcerconstants.TransmitterLabel)
// Add the port as a label with an @ prefix. These labels are invalid otherwise
// If all policies are restricted by port numbers this will allow port-specific policies
claims.T.AppendKeyValue(enforcerconstants.PortNumberLabelString, strconv.Itoa(int(udpPacket.DestinationPort)))
report, pkt := context.SearchRcvRules(claims.T)
if pkt.Action.Rejected() {
// txLabel
d.reportUDPRejectedFlow(udpPacket, conn, txLabel, context.ManagementID(), context, collector.PolicyDrop, report, pkt)
return nil, nil, fmt.Errorf("connection rejected because of policy: %s", claims.T.String())
}
hash := udpPacket.L4FlowHash()
conn.SetState(connection.UDPSynReceived)
// conntrack
d.udpNetOrigConnectionTracker.AddOrUpdate(hash, conn)
d.udpAppReplyConnectionTracker.AddOrUpdate(udpPacket.L4ReverseFlowHash(), conn)
// Record actions
conn.ReportFlowPolicy = report
conn.PacketFlowPolicy = pkt
return pkt, claims, nil
}
func (d *Datapath) processNetworkUDPSynAckPacket(udpPacket *packet.Packet, context *pucontext.PUContext, conn *connection.UDPConnection) (action interface{}, claims *tokens.ConnectionClaims, err error) {
// Packets that have authorization information go through the auth path
// Decode the JWT token using the context key
claims, err = d.tokenAccessor.ParsePacketToken(&conn.Auth, udpPacket.ReadUDPToken())
if err != nil {
d.reportUDPRejectedFlow(udpPacket, nil, collector.DefaultEndPoint, context.ManagementID(), context, collector.MissingToken, nil, nil)
return nil, nil, fmt.Errorf("SynAck packet dropped because of bad claims: %s", err)
}
if claims == nil {
d.reportUDPRejectedFlow(udpPacket, nil, collector.DefaultEndPoint, context.ManagementID(), context, collector.MissingToken, nil, nil)
return nil, nil, errors.New("SynAck packet dropped because of no claims")
}
report, pkt := context.SearchTxtRules(claims.T, !d.mutualAuthorization)
if pkt.Action.Rejected() {
d.reportUDPRejectedFlow(udpPacket, conn, context.ManagementID(), conn.Auth.RemoteContextID, context, collector.PolicyDrop, report, pkt)
return nil, nil, fmt.Errorf("dropping because of reject rule on transmitter: %s", claims.T.String())
}
conn.SetState(connection.UDPSynAckReceived)
// conntrack
d.udpNetReplyConnectionTracker.AddOrUpdate(udpPacket.L4FlowHash(), conn)
return pkt, claims, nil
}
func (d *Datapath) processNetworkUDPAckPacket(udpPacket *packet.Packet, context *pucontext.PUContext, conn *connection.UDPConnection) (action interface{}, claims *tokens.ConnectionClaims, err error) {
_, err = d.tokenAccessor.ParseAckToken(&conn.Auth, udpPacket.ReadUDPToken())
if err != nil {
d.reportUDPRejectedFlow(udpPacket, conn, conn.Auth.RemoteContextID, context.ManagementID(), context, collector.PolicyDrop, conn.ReportFlowPolicy, conn.PacketFlowPolicy)
return nil, nil, fmt.Errorf("ack packet dropped because signature validation failed: %s", err)
}
conn.SetState(connection.UDPAckReceived)
if !conn.ServiceConnection {
zap.L().Debug("Plumb conntrack rule for flow:", zap.String("flow", udpPacket.L4FlowHash()))
// Plumb connmark rule here.
if err := d.conntrackHdl.ConntrackTableUpdateMark(
udpPacket.DestinationAddress.String(),
udpPacket.SourceAddress.String(),
udpPacket.IPProto,
udpPacket.DestinationPort,
udpPacket.SourcePort,
constants.DefaultConnMark,
); err != nil {
zap.L().Error("Failed to update conntrack table after ack packet")
}
}
d.reportUDPAcceptedFlow(udpPacket, conn, conn.Auth.RemoteContextID, context.ManagementID(), context, conn.ReportFlowPolicy, conn.PacketFlowPolicy)
return nil, nil, nil
}