Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Laborator 10
Exercitiul 1
Dorim sa afisam IP-ul si portul pentru pachetele ce au ca sursa host-ul. Pentru a captura pachetele este nevoie sa atasam un hook. L-am inregistrat in init-ul modulului folosind dupa cum este sugerat
init_net(network namespace), dezalocarea se face in functia deexita modulului. Dupa aceea am initializat structuranf_hook_opssi am definit functia de hook,my_nf_hookfn.In implementarea functiei
my_nf_hookfnam utilizat utilizat bufferul pachetului (skb) pentru a identifica headerele de IP si TCP determinand din acestea adresa IP si portul.Pentru testare observam output-ul:
Exercitiul 2
In functia
ioctlpreluam din userspace adresa IP destinatie si marcam citirea prin marcarea variabilei atomiceioctl_set. Am completat functiatest_daddrverificand ca a fost primita adresa din userspace (flag-ul e setat); apoi am verificat egalitatea dintre adresa primita din userspace si cea curenta din header-ul IP. De asemenea, am modificat functiamy_nf_hookfn.Observam rezultatele obtinute:
Exercitiul 3
Am creat un socket TCP folosind
sock_create_kern. Socket-ul va "asculta" pe portul 60000 fiind initializat folosind operatiilebindsilisten. M-am ghidat dupa net/socket.c.Observam corectitudinea din output-ul scriptului de test:
Exercitiul 4
Am creat un nou socket (lite) pentru a asigura conexiune externa pe care o va accepta. In cazul in care apelul accept va returna -EAGAIN, atunci se va reincerca apelul de accept. Folosind
getname, vom prelua socketul destinatie si vom printa portul si adresa acesuia.Exercitiul 5
Am creat un socket pentru protocolul UDP si l-am initializat prin apelul
bind. Pentru a trimite mesajul am completat functiamy_udp_msgsendsi am atribuit structuriiiovec(user space data) buffer-ul cu mesajul si dimensiunea acestuia, in apelulkernel_sendmsgi-am facut un cast lakvec(kernel space data).Output-ul generat de scriptul de testare: