-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbypass.py
executable file
·35 lines (27 loc) · 1.08 KB
/
bypass.py
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
#!/usr/bin/env python
from main import PKT_DIR_INCOMING, PKT_DIR_OUTGOING
import socket
import struct
import time
class Firewall:
def __init__(self, config, iface_int, iface_ext):
self.iface_int = iface_int
self.iface_ext = iface_ext
print 'bypass mode!'
def handle_packet(self, pkt_dir, pkt):
# The example code here prints out the source/destination IP addresses,
# which is unnecessary for your submission.
src_ip = pkt[12:16]
dst_ip = pkt[16:20]
ipid, = struct.unpack('!H', pkt[4:6]) # IP identifier (big endian)
if pkt_dir == PKT_DIR_INCOMING:
dir_str = 'incoming'
else:
dir_str = 'outgoing'
print '%s len=%4dB, IPID=%5d %15s -> %15s' % (dir_str, len(pkt), ipid,
socket.inet_ntoa(src_ip), socket.inet_ntoa(dst_ip))
# ... and simply allow the packet.
if pkt_dir == PKT_DIR_INCOMING:
self.iface_int.send_ip_packet(pkt)
elif pkt_dir == PKT_DIR_OUTGOING:
self.iface_ext.send_ip_packet(pkt)