Commit d1324ac2 authored by Mauricio Vasquez B's avatar Mauricio Vasquez B

remove trailing white spaces from source code files

Trailing white spaces cause problems with git.
Signed-off-by: default avatarMauricio Vasquez B <mauricio.vasquez@polito.it>
parent fc4d4646
......@@ -35,7 +35,7 @@ int on_context_switch(struct pt_regs *ctx) {
event.pid = bpf_get_current_pid_tgid();
bpf_get_current_comm(&event.name, sizeof(event.name));
bpf_usdt_readarg(1, ctx, &event.old_addr);
bpf_usdt_readarg(2, ctx, &event.new_addr);
......
......@@ -34,7 +34,7 @@ local prog = bpf.socket('lo', function (skb)
-- Fetch 4 bytes of TCP data and compare
local h = data(0, 4)
if h == 'HTTP' or h == 'GET ' or
h == 'POST' or h == 'PUT ' or
h == 'POST' or h == 'PUT ' or
h == 'HEAD' or h == 'DELE' then
-- If hash key doesn't exist, create it
-- otherwise increment counter
......
......@@ -2,21 +2,21 @@
#include <net/sock.h>
#include <bcc/proto.h>
#define IP_TCP 6
#define IP_TCP 6
#define ETH_HLEN 14
struct Key {
u32 src_ip; //source ip
u32 dst_ip; //destination ip
unsigned short src_port; //source port
unsigned short dst_port; //destination port
unsigned short dst_port; //destination port
};
struct Leaf {
int timestamp; //timestamp in ns
};
//BPF_TABLE(map_type, key_type, leaf_type, table_name, num_entry)
//BPF_TABLE(map_type, key_type, leaf_type, table_name, num_entry)
//map <Key, Leaf>
//tracing sessions having same Key(dst_ip, src_ip, dst_port,src_port)
BPF_HASH(sessions, struct Key, struct Leaf, 1024);
......@@ -40,7 +40,7 @@ int http_filter(struct __sk_buff *skb) {
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
//filter IP packets (ethernet type = 0x0800)
if (!(ethernet->type == 0x0800)) {
goto DROP;
goto DROP;
}
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
......@@ -69,16 +69,16 @@ int http_filter(struct __sk_buff *skb) {
//value to multiply * 4
//e.g. ip->hlen = 5 ; IP Header Length = 5 x 4 byte = 20 byte
ip_header_length = ip->hlen << 2; //SHL 2 -> *4 multiply
//calculate tcp header length
//value to multiply *4
//e.g. tcp->offset = 5 ; TCP Header Length = 5 x 4 byte = 20 byte
tcp_header_length = tcp->offset << 2; //SHL 2 -> *4 multiply
//calculate patload offset and length
payload_offset = ETH_HLEN + ip_header_length + tcp_header_length;
payload_offset = ETH_HLEN + ip_header_length + tcp_header_length;
payload_length = ip->tlen - ip_header_length - tcp_header_length;
//http://stackoverflow.com/questions/25047905/http-request-minimum-size-in-bytes
//minimum length of http request is always geater than 7 bytes
//avoid invalid access memory
......
......@@ -3,7 +3,7 @@
#Bertrone Matteo - Polytechnic of Turin
#November 2015
#
#eBPF application that parses HTTP packets
#eBPF application that parses HTTP packets
#and extracts (and prints on screen) the URL contained in the GET/POST request.
#
#eBPF program http_filter is used as SOCKET_FILTER attached to eth0 interface.
......@@ -38,7 +38,7 @@ def toHex(s):
if len(hv) == 1:
hv = '0'+hv
lst.append(hv)
return reduce(lambda x,y:x+y, lst)
#print str until CR+LF
......@@ -50,7 +50,7 @@ def printUntilCRLF(str):
return
print ("%c" % (str[k]), end = "")
print("")
return
return
#cleanup function
def cleanup():
......@@ -71,7 +71,7 @@ def cleanup():
del bpf_sessions[key]
except:
print("cleanup exception.")
return
return
#args
def usage():
......@@ -155,9 +155,9 @@ while 1:
#convert packet into bytearray
packet_bytearray = bytearray(packet_str)
#ethernet header length
ETH_HLEN = 14
ETH_HLEN = 14
#IP HEADER
#https://tools.ietf.org/html/rfc791
......@@ -166,18 +166,18 @@ while 1:
# |Version| IHL |Type of Service| Total Length |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
#IHL : Internet Header Length is the length of the internet header
#IHL : Internet Header Length is the length of the internet header
#value to multiply * 4 byte
#e.g. IHL = 5 ; IP Header Length = 5 * 4 byte = 20 byte
#
#Total length: This 16-bit field defines the entire packet size,
#Total length: This 16-bit field defines the entire packet size,
#including header and data, in bytes.
#calculate packet total length
total_length = packet_bytearray[ETH_HLEN + 2] #load MSB
total_length = total_length << 8 #shift MSB
total_length = total_length + packet_bytearray[ETH_HLEN+3] #add LSB
#calculate ip header length
ip_header_length = packet_bytearray[ETH_HLEN] #load Byte
ip_header_length = ip_header_length & 0x0F #mask bits 0..3
......@@ -189,18 +189,18 @@ while 1:
ip_src = int(toHex(ip_src_str),16)
ip_dst = int(toHex(ip_dst_str),16)
#TCP HEADER
#TCP HEADER
#https://www.rfc-editor.org/rfc/rfc793.txt
# 12 13 14 15
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
# 12 13 14 15
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Data | |U|A|P|R|S|F| |
# | Offset| Reserved |R|C|S|S|Y|I| Window |
# | | |G|K|H|T|N|N| |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
#Data Offset: This indicates where the data begins.
#Data Offset: This indicates where the data begins.
#The TCP header is an integral number of 32 bits long.
#value to multiply * 4 byte
#e.g. DataOffset = 5 ; TCP Header Length = 5 * 4 byte = 20 byte
......@@ -209,17 +209,17 @@ while 1:
tcp_header_length = packet_bytearray[ETH_HLEN + ip_header_length + 12] #load Byte
tcp_header_length = tcp_header_length & 0xF0 #mask bit 4..7
tcp_header_length = tcp_header_length >> 2 #SHR 4 ; SHL 2 -> SHR 2
#retrieve port source/dest
port_src_str = packet_str[ETH_HLEN+ip_header_length:ETH_HLEN+ip_header_length+2]
port_dst_str = packet_str[ETH_HLEN+ip_header_length+2:ETH_HLEN+ip_header_length+4]
port_src = int(toHex(port_src_str),16)
port_dst = int(toHex(port_dst_str),16)
#calculate payload offset
payload_offset = ETH_HLEN + ip_header_length + tcp_header_length
#payload_string contains only packet payload
payload_string = packet_str[(payload_offset):(len(packet_bytearray))]
......@@ -238,14 +238,14 @@ while 1:
#url entirely contained in first packet -> print it all
printUntilCRLF(payload_string)
#delete current_Key from bpf_sessions, url already printed. current session not useful anymore
#delete current_Key from bpf_sessions, url already printed. current session not useful anymore
try:
del bpf_sessions[current_Key]
except:
print ("error during delete from bpf map ")
else:
#url NOT entirely contained in first packet
#not found \r\n in payload.
else:
#url NOT entirely contained in first packet
#not found \r\n in payload.
#save current part of the payload_string in dictionary <key(ips,ipd,ports,portd),payload_string>
local_dictionary[binascii.hexlify(current_Key)] = payload_string
else:
......@@ -253,17 +253,17 @@ while 1:
#check if the packet belong to a session saved in bpf_sessions
if (current_Key in bpf_sessions):
#check id the packet belong to a session saved in local_dictionary
#check id the packet belong to a session saved in local_dictionary
#(local_dictionary mantains HTTP GET/POST url not printed yet because splitted in N packets)
if (binascii.hexlify(current_Key) in local_dictionary):
#first part of the HTTP GET/POST url is already present in local dictionary (prev_payload_string)
prev_payload_string = local_dictionary[binascii.hexlify(current_Key)]
#looking for CR+LF in current packet.
#looking for CR+LF in current packet.
if (crlf in payload_string):
#last packet. containing last part of HTTP GET/POST url splitted in N packets.
#append current payload
prev_payload_string += payload_string
#print HTTP GET/POST url
#print HTTP GET/POST url
printUntilCRLF(prev_payload_string)
#clean bpf_sessions & local_dictionary
try:
......@@ -284,7 +284,7 @@ while 1:
except:
print ("error deleting from map or dict")
#update dictionary
local_dictionary[binascii.hexlify(current_Key)] = prev_payload_string
local_dictionary[binascii.hexlify(current_Key)] = prev_payload_string
else:
#first part of the HTTP GET/POST url is NOT present in local dictionary
#bpf_sessions contains invalid entry -> delete it
......
......@@ -2,7 +2,7 @@
#include <net/sock.h>
#include <bcc/proto.h>
#define IP_TCP 6
#define IP_TCP 6
#define ETH_HLEN 14
/*eBPF program.
......@@ -20,7 +20,7 @@ int http_filter(struct __sk_buff *skb) {
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
//filter IP packets (ethernet type = 0x0800)
if (!(ethernet->type == 0x0800)) {
goto DROP;
goto DROP;
}
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
......@@ -40,16 +40,16 @@ int http_filter(struct __sk_buff *skb) {
//value to multiply * 4
//e.g. ip->hlen = 5 ; IP Header Length = 5 x 4 byte = 20 byte
ip_header_length = ip->hlen << 2; //SHL 2 -> *4 multiply
//calculate tcp header length
//value to multiply *4
//e.g. tcp->offset = 5 ; TCP Header Length = 5 x 4 byte = 20 byte
tcp_header_length = tcp->offset << 2; //SHL 2 -> *4 multiply
//calculate patload offset and length
payload_offset = ETH_HLEN + ip_header_length + tcp_header_length;
payload_offset = ETH_HLEN + ip_header_length + tcp_header_length;
payload_length = ip->tlen - ip_header_length - tcp_header_length;
//http://stackoverflow.com/questions/25047905/http-request-minimum-size-in-bytes
//minimum length of http request is always geater than 7 bytes
//avoid invalid access memory
......
......@@ -3,7 +3,7 @@
#Bertrone Matteo - Polytechnic of Turin
#November 2015
#
#eBPF application that parses HTTP packets
#eBPF application that parses HTTP packets
#and extracts (and prints on screen) the URL contained in the GET/POST request.
#
#eBPF program http_filter is used as SOCKET_FILTER attached to eth0 interface.
......@@ -90,9 +90,9 @@ while 1:
#convert packet into bytearray
packet_bytearray = bytearray(packet_str)
#ethernet header length
ETH_HLEN = 14
ETH_HLEN = 14
#IP HEADER
#https://tools.ietf.org/html/rfc791
......@@ -101,34 +101,34 @@ while 1:
# |Version| IHL |Type of Service| Total Length |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
#IHL : Internet Header Length is the length of the internet header
#IHL : Internet Header Length is the length of the internet header
#value to multiply * 4 byte
#e.g. IHL = 5 ; IP Header Length = 5 * 4 byte = 20 byte
#
#Total length: This 16-bit field defines the entire packet size,
#Total length: This 16-bit field defines the entire packet size,
#including header and data, in bytes.
#calculate packet total length
total_length = packet_bytearray[ETH_HLEN + 2] #load MSB
total_length = total_length << 8 #shift MSB
total_length = total_length + packet_bytearray[ETH_HLEN+3] #add LSB
#calculate ip header length
ip_header_length = packet_bytearray[ETH_HLEN] #load Byte
ip_header_length = ip_header_length & 0x0F #mask bits 0..3
ip_header_length = ip_header_length << 2 #shift to obtain length
#TCP HEADER
#TCP HEADER
#https://www.rfc-editor.org/rfc/rfc793.txt
# 12 13 14 15
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
# 12 13 14 15
# 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
# | Data | |U|A|P|R|S|F| |
# | Offset| Reserved |R|C|S|S|Y|I| Window |
# | | |G|K|H|T|N|N| |
# +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
#
#Data Offset: This indicates where the data begins.
#Data Offset: This indicates where the data begins.
#The TCP header is an integral number of 32 bits long.
#value to multiply * 4 byte
#e.g. DataOffset = 5 ; TCP Header Length = 5 * 4 byte = 20 byte
......@@ -137,10 +137,10 @@ while 1:
tcp_header_length = packet_bytearray[ETH_HLEN + ip_header_length + 12] #load Byte
tcp_header_length = tcp_header_length & 0xF0 #mask bit 4..7
tcp_header_length = tcp_header_length >> 2 #SHR 4 ; SHL 2 -> SHR 2
#calculate payload offset
payload_offset = ETH_HLEN + ip_header_length + tcp_header_length
#print first line of the HTTP GET/POST request
#line ends with 0xOD 0xOA (\r\n)
#(if we want to print all the header print until \r\n\r\n)
......
......@@ -10,7 +10,7 @@
#
# Copyright (c) PLUMgrid, Inc.
# Licensed under the Apache License, Version 2.0 (the "License")
#
#
# Example output:
# $ sudo ./strlen_hist.py
# 22:12:52
......
......@@ -122,7 +122,7 @@ static inline bool _is_tracepoint_struct_type(string const& type_name,
// (?:struct|class)\s+tracepoint__(\S+)__(\S+)
// Not using std::regex because older versions of GCC don't support it yet.
// E.g., the libstdc++ that ships with Ubuntu 14.04.
auto first_space_pos = type_name.find_first_of("\t ");
if (first_space_pos == string::npos)
return false;
......
......@@ -53,7 +53,7 @@ class TracepointTypeVisitor :
clang::ASTContext &C;
clang::DiagnosticsEngine &diag_;
clang::Rewriter &rewriter_;
llvm::raw_ostream &out_;
llvm::raw_ostream &out_;
};
class TracepointTypeConsumer : public clang::ASTConsumer {
......
......@@ -3,10 +3,10 @@
class CompilationException(Exception):
"""Signals an error during compilation"""
def __init__(self, isBug, format, *message):
def __init__(self, isBug, format, *message):
# isBug: indicates that this is a compiler bug
super(CompilationException, self).__init__()
assert isinstance(format, str)
assert isinstance(isBug, bool)
self.message = message
......
......@@ -225,10 +225,10 @@ class EbpfAction(EbpfActionBase):
dst.asString,
src.asString,
size / 8)
elif (callee.name == "add" or
callee.name == "bit_and" or
callee.name == "bit_or" or
callee.name == "bit_xor" or
elif (callee.name == "add" or
callee.name == "bit_and" or
callee.name == "bit_or" or
callee.name == "bit_xor" or
callee.name == "subtract"):
size = self.checkSize(callee,
[a.widthInBits() for a in args],
......@@ -247,7 +247,7 @@ class EbpfAction(EbpfActionBase):
args[1].asString,
op,
args[2].asString)
elif (callee.name == "add_to_field" or
elif (callee.name == "add_to_field" or
callee.name == "subtract_from_field"):
size = self.checkSize(callee,
[a.widthInBits() for a in args],
......
......@@ -50,7 +50,7 @@ class EbpfConditional(object):
"{0}.{1}.{2}", base, einstance.name, node.name)
else:
raise CompilationException(True, "{0} Unexpected expression ", node)
def emitExpression(self, expression, serializer, program, toplevel):
assert isinstance(serializer, ProgramSerializer)
assert isinstance(program, ebpfProgram.EbpfProgram)
......@@ -59,9 +59,9 @@ class EbpfConditional(object):
left = expression.left
op = expression.op
right = expression.right
assert isinstance(op, str)
if op == "valid":
self.emitNode(right, serializer, program)
serializer.append(".valid")
......
......@@ -27,7 +27,7 @@ class EbpfCounter(object):
self.dataMapName = self.name
if ((hlircounter.binding is None) or
if ((hlircounter.binding is None) or
(hlircounter.binding[0] != P4_DIRECT)):
raise NotSupportedException(
"{0}: counter which is not direct", hlircounter)
......
......@@ -19,7 +19,7 @@ from compilationException import *
class EbpfProgram(object):
def __init__(self, name, hlir, isRouter, config):
"""Representation of an EbpfProgram (in fact,
"""Representation of an EbpfProgram (in fact,
a C program that is converted to EBPF)"""
assert isinstance(hlir, HLIR)
assert isinstance(isRouter, bool)
......
......@@ -51,7 +51,7 @@ class EbpfScalarType(EbpfType):
return 4
else:
return 1 # Char array
def serialize(self, serializer):
assert isinstance(serializer, ProgramSerializer)
serializer.append(self.asString())
......
......@@ -84,8 +84,8 @@ class EbpfTableKey(object):
matchType = f[1]
mask = f[2]
if ((matchType is p4_match_type.P4_MATCH_TERNARY) or
(matchType is p4_match_type.P4_MATCH_LPM) or
if ((matchType is p4_match_type.P4_MATCH_TERNARY) or
(matchType is p4_match_type.P4_MATCH_LPM) or
(matchType is p4_match_type.P4_MATCH_RANGE)):
raise NotSupportedException(
False, "Match type {0}", matchType)
......@@ -126,7 +126,7 @@ class EbpfTableKey(object):
def fieldRank(field):
assert isinstance(field, EbpfTableKeyField)
return field.field.type.alignment()
def serializeType(self, serializer, keyTypeName):
assert isinstance(serializer, ProgramSerializer)
serializer.emitIndent()
......@@ -193,7 +193,7 @@ class EbpfTable(object):
assert isinstance(ctr, ebpfCounter.EbpfCounter)
self.counters.append(ctr)
if (len(hlirtable.attached_meters) > 0 or
if (len(hlirtable.attached_meters) > 0 or
len(hlirtable.attached_registers) > 0):
program.emitWarning("{0}: meters/registers {1}; ignored",
hlirtable, NotSupportedException.archError)
......
......@@ -6,7 +6,7 @@
# Compiler from P4 to EBPF
# (See http://www.slideshare.net/PLUMgrid/ebpf-and-linux-networking).
# This compiler in fact generates a C source file
# which can be compiled to EBPF using the LLVM compiler
# which can be compiled to EBPF using the LLVM compiler
# with the ebpf target.
#
# Main entry point.
......
......@@ -113,7 +113,7 @@ class KernelSamplesConfig(TargetConfig):
#include "bpf_helpers.h"
"""
# Represents a target compiled by bcc that uses the TC
class BccConfig(TargetConfig):
def __init__(self):
......
......@@ -13,7 +13,7 @@ class EbpfTypeFactory(object):
name = hlirType.name
if hlirType.name in self.type_map:
retval = self.type_map[name]
if ((not asMetadata and isinstance(retval, EbpfMetadataType)) or
if ((not asMetadata and isinstance(retval, EbpfMetadataType)) or
(asMetadata and isinstance(retval, EbpfHeaderType))):
raise CompilationException(
True, "Same type used both as a header and metadata {0}",
......
......@@ -26,7 +26,7 @@ class Base(object):
def message(self, *args):
if self.verbose:
print(*args)
class Endpoint(Base):
# a network interface really
......@@ -47,7 +47,7 @@ class Endpoint(Base):
def get_ip_address(self):
return IPAddress(self.ipaddress)
class Node(Base):
# Used to represent one of clt, sw, srv
# Each lives in its own namespace
......@@ -67,7 +67,7 @@ class Node(Base):
def get_ns_name(self):
return self.name
def get_ns(self):
nsname = self.get_ns_name()
ns = NetNS(nsname)
......@@ -100,7 +100,7 @@ class NetworkBase(Base):
Base.__init__(self)
self.ipr = IPRoute()
self.nodes = []
def add_node(self, node):
assert isinstance(node, Node)
self.nodes.append(node)
......@@ -123,7 +123,7 @@ class NetworkBase(Base):
# Ask a node to set the specified interface address
if address is None:
return
assert isinstance(node, Node)
command = ["ip", "addr", "add", str(address) + "/" + str(mask),
"dev", str(ifname)]
......@@ -132,7 +132,7 @@ class NetworkBase(Base):
def create_link(self, src, dest):
assert isinstance(src, Endpoint)
assert isinstance(dest, Endpoint)
assert isinstance(dest, Endpoint)
ifname = self.get_interface_name(src.parent, dest.parent)
destname = self.get_interface_name(dest.parent, src.parent)
......@@ -150,7 +150,7 @@ class NetworkBase(Base):
# lost of set prior to moving to namespace
self.set_interface_ipaddress(
src.parent, ifname, src.ipaddress , src.prefixlen)
# Sef destination endpoint information
ix = self.get_interface(destname)
self.ipr.link("set", index=ix, address=dest.mac_addr)
......@@ -178,7 +178,7 @@ class NetworkBase(Base):
n.remove()
self.ipr.close()
### Here begins the concrete instantiation of the network
# Network setup:
# Each of these is a separate namespace.
......@@ -191,7 +191,7 @@ class NetworkBase(Base):
# ---------- -------- ---------
# 10.0.0.11 10.0.0.10
#
class SimulatedNetwork(NetworkBase):
def __init__(self):
NetworkBase.__init__(self)
......@@ -219,7 +219,7 @@ class SimulatedNetwork(NetworkBase):
assert isinstance(node, Node)
assert isinstance(args, list)
torun = __file__
args.insert(0, torun)
args.insert(0, torun)
args.insert(1, method)
return node.execute(args) # runs the command argv[0] method args
......@@ -240,7 +240,7 @@ class SimulatedNetwork(NetworkBase):
self.message("Set ARP mappings")
self.client.set_arp(self.server_endpoint)
self.server.set_arp(self.client_endpoint)
def setup_switch(self):
# This method is run in the switch namespace.
self.message("Compiling and loading BPF program")
......@@ -254,7 +254,7 @@ class SimulatedNetwork(NetworkBase):
routing_tbl = b.get_table("routing")
routing_miss_tbl = b.get_table("ebpf_routing_miss")
cnt_tbl = b.get_table("cnt")
self.message("Hooking up BPF classifiers using TC")
interfname = self.get_interface_name(self.switch, self.server)
......@@ -268,7 +268,7 @@ class SimulatedNetwork(NetworkBase):
self.ipr.tc("add", "ingress", sw_clt_idx, "ffff:")
self.ipr.tc("add-filter", "bpf", sw_clt_idx, ":1", fd=fn.fd,
name=fn.name, parent="ffff:", action="ok", classid=1)
self.message("Populating tables from the control plane")
cltip = self.client_endpoint.get_ip_address()
srvip = self.server_endpoint.get_ip_address()
......@@ -276,17 +276,17 @@ class SimulatedNetwork(NetworkBase):
# BCC does not support tbl.Leaf when the type contains a union,
# so we have to make up the value type manually. Unfortunately
# these sizes are not portable...
class Forward(ctypes.Structure):
_fields_ = [("port", ctypes.c_ushort)]
class Nop(ctypes.Structure):
_fields_ = []
class Union(ctypes.Union):
_fields_ = [("nop", Nop),
("forward", Forward)]
class Value(ctypes.Structure):
_fields_ = [("action", ctypes.c_uint),
("u", Union)]
......@@ -301,14 +301,14 @@ class SimulatedNetwork(NetworkBase):
v1 = Value()
v1.action = 1
v1.u.forward.port = sw_clt_idx
v2 = Value()
v2.action = 1;
v2.u.forward.port = sw_srv_idx
routing_tbl[routing_tbl.Key(int(cltip))] = v1
routing_tbl[routing_tbl.Key(int(srvip))] = v2
self.message("Dumping table contents")
for key, leaf in routing_tbl.items():
self.message(str(IPAddress(key.key_field_0)),
......@@ -322,7 +322,7 @@ class SimulatedNetwork(NetworkBase):
raise Exception("Test failed")
else:
print("Test succeeded!")
def prepare_switch(self):
self.message("Configuring switch")
# Re-invokes this script in the switch namespace;
......@@ -331,7 +331,7 @@ class SimulatedNetwork(NetworkBase):
# but in the switch namespace
self.run_method_in_node(self.switch, "setup_switch", [])
def compile(source, destination):
try:
status = subprocess.call(
......@@ -344,7 +344,7 @@ def compile(source, destination):
except OSError as e:
print("Execution failed:", e, file=sys.stderr)
raise e
def start_simulation():
compile("testprograms/simple.p4", "simple.c")
network = SimulatedNetwork()
......
......@@ -27,7 +27,7 @@ def set_error(kind, file, error):
def is_root():
# Is this code portable?
return os.getuid() == 0
def main():
testpath = "testprograms"
destFolder = "testoutputs"
......@@ -40,7 +40,7 @@ def main():
print "Loading EBPF programs requires root priviledge."
print "Will only test compilation, not loading."
print "(Run with sudo to test program loading.)"
for f in files:
path = os.path.join(testpath, f)
......@@ -62,14 +62,14 @@ def main():
else:
# Try to load the compiled function
if is_root():
try:
try:
print("Compiling and loading BPF program")
b = BPF(src_file=destname, debug=0)
fn = b.load_func("ebpf_filter", BPF.SCHED_CLS)
except Exception as e:
print(e)
set_error("BPF error", path, str(e))
filesDone += 1
print "Compiled", filesDone, "files", errors, "errors"
......@@ -78,7 +78,7 @@ def main():
for v in filesFailed[key]:
print "\t", v
exit(len(filesFailed) != 0)
if __name__ == "__main__":
main()
......@@ -346,7 +346,7 @@ static int bpf_attach_tracing_event(int progfd, const char *event_path,
void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, const char *ev_name,
const char *fn_name,
pid_t pid, int cpu, int group_fd,
perf_reader_cb cb, void *cb_cookie)
perf_reader_cb cb, void *cb_cookie)
{
int kfd;
char buf[256];
......@@ -367,7 +367,7 @@ void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, con
goto error;
}
snprintf(buf, sizeof(buf), "%c:%ss/%s %s", attach_type==BPF_PROBE_ENTRY ? 'p' : 'r',
snprintf(buf, sizeof(buf), "%c:%ss/%s %s", attach_type==BPF_PROBE_ENTRY ? 'p' : 'r',
event_type, new_name, fn_name);
if (write(kfd, buf, strlen(buf)) < 0) {
if (errno == EINVAL)
......@@ -380,10 +380,10 @@ void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type, con
if (access("/sys/kernel/debug/tracing/instances", F_OK) != -1) {
snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/instances/bcc_%d", getpid());
if (access(buf, F_OK) == -1) {
if (mkdir(buf, 0755) == -1)
if (mkdir(buf, 0755) == -1)
goto retry;
}
n = snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/instances/bcc_%d/events/%ss/%s",
n = snprintf(buf, sizeof(buf), "/sys/kernel/debug/tracing/instances/bcc_%d/events/%ss/%s",
getpid(), event_type, new_name);
if (n < sizeof(buf) && bpf_attach_tracing_event(progfd, buf, reader, pid, cpu, group_fd) == 0)
goto out;
......@@ -406,7 +406,7 @@ error:
void * bpf_attach_uprobe(int progfd, enum bpf_probe_attach_type attach_type, const char *ev_name,
const char *binary_path, uint64_t offset,
pid_t pid, int cpu, int group_fd,
perf_reader_cb cb, void *cb_cookie)
perf_reader_cb cb, void *cb_cookie)
{
int kfd;
char buf[PATH_MAX];
......@@ -428,7 +428,7 @@ void * bpf_attach_uprobe(int progfd, enum bpf_probe_attach_type attach_type, con
goto error;
}
n = snprintf(buf, sizeof(buf), "%c:%ss/%s %s:0x%lx", attach_type==BPF_PROBE_ENTRY ? 'p' : 'r',
n = snprintf(buf, sizeof(buf), "%c:%ss/%s %s:0x%lx", attach_type==BPF_PROBE_ENTRY ? 'p' : 'r',
event_type, new_name, binary_path, offset);
if (n >= sizeof(buf)) {
close(kfd);
......
......@@ -50,7 +50,7 @@ typedef void (*perf_reader_cb)(void *cb_cookie, int pid, uint64_t callchain_num,
typedef void (*perf_reader_raw_cb)(void *cb_cookie, void *raw, int raw_size);
typedef void (*perf_reader_lost_cb)(uint64_t lost);
void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type,
void * bpf_attach_kprobe(int progfd, enum bpf_probe_attach_type attach_type,
const char *ev_name, const char *fn_name,
pid_t pid, int cpu, int group_fd,
perf_reader_cb cb, void *cb_cookie);
......
......@@ -258,7 +258,7 @@ local function valloc(size, blank)
stack_top = math.ceil(stack_top/8)*8
-- Current kernel version doesn't support ARG_PTR_TO_RAW_STACK
-- so we always need to have memory initialized, remove this when supported
if blank then
if blank then
if type(blank) == 'string' then
local sp = 0
while sp < size do
......@@ -276,7 +276,7 @@ local function valloc(size, blank)
emit(BPF.MEM + BPF.STX + BPF.DW, 10, 0, -sp, 0)
end
else error('NYI: will with unknown type '..type(blank)) end
end
end
return stack_top
end
......@@ -604,7 +604,7 @@ local function MAP_DEL(map_var, key, key_imm)
end
local function MAP_SET(map_var, key, key_imm, src)
local map = V[map_var].const
local map = V[map_var].const
-- Delete when setting nil
if V[src].type == ffi.typeof('void') then
return MAP_DEL(map_var, key, key_imm)
......
......@@ -205,7 +205,7 @@ builtins[ffi.copy] = function (e, ret, dst, src)
-- TODO: identify cheap register move
-- TODO: identify copy to/from stack
error('NYI: ffi.copy(dst, src) - src is neither BPF map/socket buffer or probe')
end
end
end
-- print(format, ...) builtin changes semantics from Lua print(...)
-- the first parameter has to be format and only reduced set of conversion specificers
......
......@@ -170,7 +170,7 @@ function M.typename(v)
return string.match(tostring(ffi.typeof(v)), '<([^>]+)')
end
-- Reflect if cdata type can be pointer (accepts array or pointer)
-- Reflect if cdata type can be pointer (accepts array or pointer)
function M.isptr(v, noarray)
local ctname = M.typename(v)
if ctname then
......
......@@ -227,7 +227,7 @@ ffi.metatype('struct Elf_object', {
end
-- Match symbol name against pattern
if pattern and string.match(name, k) or k == name then
return sym[0]
return sym[0]
end
end
end
......
......@@ -222,7 +222,7 @@ local function next_offset(e, var, type, off, mask, shift)
-- Finalize relative offset
if mask then
e.emit(BPF.ALU + BPF.AND + BPF.K, tmp_reg, 0, 0, mask)
end
end
if shift then
local op = BPF.LSH
if shift < 0 then
......
......@@ -27,7 +27,7 @@ repeat = """
end = """
y = t1.lookup(&x);
x = *y;
return 0;
return 0;
}
"""
for i in range(0,300):
......@@ -42,7 +42,7 @@ class TestBPFProgLoad(TestCase):
def tearDown(self):
self.fp.close()
def test_log_debug(self):
b = BPF(text=text, debug=2)
......
......@@ -130,7 +130,7 @@ static int br_common(struct __sk_buff *skb, int which_br) {
index = 0;
if (which_br == 1)
rtrif_p = br1_rtr.lookup(&index);
else
else
rtrif_p = br2_rtr.lookup(&index);
if (rtrif_p)
bpf_clone_redirect(skb, *rtrif_p, 0);
......
......@@ -13,7 +13,7 @@
#
# The vm1, vm2 and router are implemented as namespaces.
# The bridge is implemented with limited functionality in bpf program.
#
#
# vm1 and vm2 are in different subnet. For vm1 to communicate to vm2,
# the packet will have to travel from vm1 to pem, bridge1, router, bridge2, pem, and
# then come to vm2.
......@@ -33,7 +33,7 @@
# 8: PING 200.1.1.1 (200.1.1.1) 56(84) bytes of data.
# 8: 64 bytes from 200.1.1.1: icmp_req=1 ttl=63 time=0.074 ms
# 8: 64 bytes from 200.1.1.1: icmp_req=2 ttl=63 time=0.061 ms
# 8:
# 8:
# 8: --- 200.1.1.1 ping statistics ---
# 8: 2 packets transmitted, 2 received, 0% packet loss, time 999ms
# 8: rtt min/avg/max/mdev = 0.061/0.067/0.074/0.010 ms
......@@ -41,24 +41,24 @@
# 8: [ 5] 0.0- 1.0 sec 4.00 GBytes 34.3 Gbits/sec
# 8: Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC
# 8: MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 200.1.1.1 (200.1.1.1) port 0 AF_INET : demo
# 8: Recv Send Send
# 8: Socket Socket Message Elapsed
# 8: Size Size Size Time Throughput
# 8: bytes bytes bytes secs. 10^6bits/sec
# 8:
# 8: 87380 16384 65160 1.00 41991.68
# 8: Recv Send Send
# 8: Socket Socket Message Elapsed
# 8: Size Size Size Time Throughput
# 8: bytes bytes bytes secs. 10^6bits/sec
# 8:
# 8: 87380 16384 65160 1.00 41991.68
# 8: MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 200.1.1.1 (200.1.1.1) port 0 AF_INET : demo : first burst 0
# 8: Local /Remote
# 8: Socket Size Request Resp. Elapsed Trans.
# 8: Send Recv Size Size Time Rate
# 8: bytes Bytes bytes bytes secs. per sec
# 8:
# 8: 16384 87380 1 1 1.00 48645.53
# 8: 16384 87380
# 8: Send Recv Size Size Time Rate
# 8: bytes Bytes bytes bytes secs. per sec
# 8:
# 8: 16384 87380 1 1 1.00 48645.53
# 8: 16384 87380
# 8: .
# 8: ----------------------------------------------------------------------
# 8: Ran 1 test in 11.296s
# 8:
# 8:
# 8: OK
from ctypes import c_uint
......
......@@ -14,7 +14,7 @@
# The vm1, vm2 and router are implemented as namespaces.
# The linux bridge device is used to provice bridge functionality.
# pem bpf will be attached to related network devices for vm1, vm1, bridge1 and bridge2.
#
#
# vm1 and vm2 are in different subnet. For vm1 to communicate to vm2,
# the packet will have to travel from vm1 to pem, bridge1, router, bridge2, pem, and
# then come to vm2.
......@@ -26,7 +26,7 @@
# 9: PING 200.1.1.1 (200.1.1.1) 56(84) bytes of data.
# 9: 64 bytes from 200.1.1.1: icmp_req=1 ttl=63 time=0.090 ms
# 9: 64 bytes from 200.1.1.1: icmp_req=2 ttl=63 time=0.032 ms
# 9:
# 9:
# 9: --- 200.1.1.1 ping statistics ---
# 9: 2 packets transmitted, 2 received, 0% packet loss, time 999ms
# 9: rtt min/avg/max/mdev = 0.032/0.061/0.090/0.029 ms
......@@ -34,24 +34,24 @@
# 9: [ 5] 0.0- 1.0 sec 3.80 GBytes 32.6 Gbits/sec
# 9: Starting netserver with host 'IN(6)ADDR_ANY' port '12865' and family AF_UNSPEC
# 9: MIGRATED TCP STREAM TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 200.1.1.1 (200.1.1.1) port 0 AF_INET : demo
# 9: Recv Send Send
# 9: Socket Socket Message Elapsed
# 9: Size Size Size Time Throughput
# 9: bytes bytes bytes secs. 10^6bits/sec
# 9:
# 9: 87380 16384 65160 1.00 39940.46
# 9: Recv Send Send
# 9: Socket Socket Message Elapsed
# 9: Size Size Size Time Throughput
# 9: bytes bytes bytes secs. 10^6bits/sec
# 9:
# 9: 87380 16384 65160 1.00 39940.46
# 9: MIGRATED TCP REQUEST/RESPONSE TEST from 0.0.0.0 (0.0.0.0) port 0 AF_INET to 200.1.1.1 (200.1.1.1) port 0 AF_INET : demo : first burst 0
# 9: Local /Remote
# 9: Socket Size Request Resp. Elapsed Trans.
# 9: Send Recv Size Size Time Rate
# 9: bytes Bytes bytes bytes secs. per sec
# 9:
# 9: 16384 87380 1 1 1.00 46387.80
# 9: 16384 87380
# 9: Send Recv Size Size Time Rate
# 9: bytes Bytes bytes bytes secs. per sec
# 9:
# 9: 16384 87380 1 1 1.00 46387.80
# 9: 16384 87380
# 9: .
# 9: ----------------------------------------------------------------------
# 9: Ran 1 test in 7.495s
# 9:
# 9:
# 9: OK
from ctypes import c_uint
......@@ -87,7 +87,7 @@ class TestBPFSocket(TestCase):
ipdb.interfaces[veth_br_2_pem].up().commit()
subprocess.call(["sysctl", "-q", "-w", "net.ipv6.conf." + veth_pem_2_br + ".disable_ipv6=1"])
subprocess.call(["sysctl", "-q", "-w", "net.ipv6.conf." + veth_br_2_pem + ".disable_ipv6=1"])
# set up the bridge and add router interface as one of its slaves
with ipdb.create(ifname=br, kind="bridge") as br1:
br1.add_port(ipdb.interfaces[veth_pem_2_br])
......
......@@ -84,7 +84,7 @@ int count(struct pt_regs *ctx) {
libc = ctypes.CDLL("libc.so.6", use_errno=True)
# Need to find path to libz.so.1
libz_path = None
libz_path = None
p = subprocess.Popen(["ldconfig", "-p"], stdout=subprocess.PIPE)
for l in p.stdout:
n = l.split()
......@@ -102,7 +102,7 @@ int count(struct pt_regs *ctx) {
if libc.unshare(0x00020000) == -1:
e = ctypes.get_errno()
raise OSError(e, errno.errorcode[e])
# Remount root MS_REC|MS_PRIVATE
if libc.mount(None, "/", None, (1<<14)|(1<<18) , None) == -1:
e = ctypes.get_errno()
......@@ -119,7 +119,7 @@ int count(struct pt_regs *ctx) {
libz.zlibVersion()
time.sleep(5)
os._exit(0)
libname = "/tmp/libz.so.1"
symname = "zlibVersion"
text = text.replace("PID", "%d" % child_pid)
......@@ -131,6 +131,6 @@ int count(struct pt_regs *ctx) {
b.detach_uretprobe(name=libname, sym=symname, pid=child_pid)
b.detach_uprobe(name=libname, sym=symname, pid=child_pid)
os.wait()
if __name__ == "__main__":
unittest.main()
......@@ -30,7 +30,7 @@ examples = """examples:
./execsnoop -x # include failed exec()s
./execsnoop -t # include timestamps
./execsnoop -n main # only print command lines containing "main"
./execsnoop -l tpkg # only print command where arguments contains "tpkg"
./execsnoop -l tpkg # only print command where arguments contains "tpkg"
"""
parser = argparse.ArgumentParser(
description="Trace exec() syscalls",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment