From: Bertrone Matteo Date: Mon, 16 May 2016 13:46:01 +0000 (-0700) Subject: invalid access fixed. parameter for specify the interface added X-Git-Tag: v0.2.0~86^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8cbc816aea77ee3e134e9efbff695cfc3ad43d1a;p=platform%2Fupstream%2Fbcc.git invalid access fixed. parameter for specify the interface added --- diff --git a/examples/networking/http_filter/http-parse-complete.c b/examples/networking/http_filter/http-parse-complete.c index 198d588..3bfc036 100644 --- a/examples/networking/http_filter/http-parse-complete.c +++ b/examples/networking/http_filter/http-parse-complete.c @@ -54,7 +54,7 @@ int http_filter(struct __sk_buff *skb) { u32 payload_offset = 0; u32 payload_length = 0; struct Key key; - struct Leaf leaf; + struct Leaf zero = {0}; struct tcp_t *tcp = cursor_advance(cursor, sizeof(*tcp)); @@ -135,10 +135,8 @@ int http_filter(struct __sk_buff *skb) { //keep the packet and send it to userspace retruning -1 HTTP_MATCH: //if not already present, insert into map - leaf.timestamp = 0; - sessions.lookup_or_init(&key, &leaf); - sessions.update(&key,&leaf); - + sessions.lookup_or_init(&key,&zero); + //send packet to userspace returning -1 KEEP: return -1; diff --git a/examples/networking/http_filter/http-parse-complete.py b/examples/networking/http_filter/http-parse-complete.py index 1d7788b..808d244 100644 --- a/examples/networking/http_filter/http-parse-complete.py +++ b/examples/networking/http_filter/http-parse-complete.py @@ -16,6 +16,7 @@ from __future__ import print_function from bcc import BPF from ctypes import * from struct import * +from sys import argv import sys import socket @@ -27,7 +28,6 @@ import time CLEANUP_N_PACKETS = 50 #run cleanup every CLEANUP_N_PACKETS packets received MAX_URL_STRING_LEN = 8192 #max url string len (usually 8K) MAX_AGE_SECONDS = 30 #max age entry in bpf_sessions map -#-----FUNCTIONS-BEGIN----------------------# #convert a bin string into a string of hex char #helper function to print raw packet in hex @@ -73,8 +73,45 @@ def cleanup(): print("cleanup exception.") return -#-----FUNCTIONS-END-------------------------# +#args +def usage(): + print("USAGE: %s [-i ]" % argv[0]) + print("") + print("Try '%s -h' for more options." % argv[0]) + exit() + +#help +def help(): + print("USAGE: %s [-i ]" % argv[0]) + print("") + print("optional arguments:") + print(" -h print this help") + print(" -i if_name select interface if_name. Default is eth0") + print("") + print("examples:") + print(" http-parse # bind socket to eth0") + print(" http-parse -i wlan0 # bind socket to wlan0") + exit() + +#arguments +interface="eth0" + +if len(argv) == 2: + if str(argv[1]) == '-h': + help() + else: + usage() + +if len(argv) == 3: + if str(argv[1]) == '-i': + interface = argv[2] + else: + usage() + +if len(argv) > 3: + usage() +print ("binding socket to '%s'" % interface) # initialize BPF - load source code from http-parse-complete.c bpf = BPF(src_file = "http-parse-complete.c",debug = 0) @@ -84,9 +121,9 @@ bpf = BPF(src_file = "http-parse-complete.c",debug = 0) #http://man7.org/linux/man-pages/man2/bpf.2.html function_http_filter = bpf.load_func("http_filter", BPF.SOCKET_FILTER) -#create raw socket, bind it to eth0 +#create raw socket, bind it to interface #attach bpf program to socket created -BPF.attach_raw_socket(function_http_filter, "eth0") +BPF.attach_raw_socket(function_http_filter, interface) #get file descriptor of the socket previously created inside BPF.attach_raw_socket socket_fd = function_http_filter.sock diff --git a/examples/networking/http_filter/http-parse-simple.py b/examples/networking/http_filter/http-parse-simple.py index 2d19d9d..81fbd4d 100644 --- a/examples/networking/http_filter/http-parse-simple.py +++ b/examples/networking/http_filter/http-parse-simple.py @@ -14,11 +14,52 @@ from __future__ import print_function from bcc import BPF +from sys import argv import sys import socket import os +#args +def usage(): + print("USAGE: %s [-i ]" % argv[0]) + print("") + print("Try '%s -h' for more options." % argv[0]) + exit() + +#help +def help(): + print("USAGE: %s [-i ]" % argv[0]) + print("") + print("optional arguments:") + print(" -h print this help") + print(" -i if_name select interface if_name. Default is eth0") + print("") + print("examples:") + print(" http-parse # bind socket to eth0") + print(" http-parse -i wlan0 # bind socket to wlan0") + exit() + +#arguments +interface="eth0" + +if len(argv) == 2: + if str(argv[1]) == '-h': + help() + else: + usage() + +if len(argv) == 3: + if str(argv[1]) == '-i': + interface = argv[2] + else: + usage() + +if len(argv) > 3: + usage() + +print ("binding socket to '%s'" % interface) + # initialize BPF - load source code from http-parse-simple.c bpf = BPF(src_file = "http-parse-simple.c",debug = 0) @@ -27,9 +68,9 @@ bpf = BPF(src_file = "http-parse-simple.c",debug = 0) #http://man7.org/linux/man-pages/man2/bpf.2.html function_http_filter = bpf.load_func("http_filter", BPF.SOCKET_FILTER) -#create raw socket, bind it to eth0 +#create raw socket, bind it to interface #attach bpf program to socket created -BPF.attach_raw_socket(function_http_filter, "eth0") +BPF.attach_raw_socket(function_http_filter, interface) #get file descriptor of the socket previously created inside BPF.attach_raw_socket socket_fd = function_http_filter.sock