Network layer
Network Layer
4-1
Dove siamo?
Network Layer
4-2
application
transport
network
link
physical
P1
application
transport
network
link
physical
application
transport
network
link
physical
P3
P4
host 1
Router
host 2
= process
= socket
= TCP <-> IP interface
Lo strato di rete
Network Layer
4-3
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
network
data link
physical
application
transport
network
data link
physical
application
transport
network
data link
physical
Modello di servizio
Network Layer
4-4
Q: Che caratteristiche fornisce questo strato al livello superiore (Trasporto)?
Architettura
IP
Modello
di servizio
best effort
Banda
no
Perdita
no
Ordine
no
Timing
no
Controllo�congestione
no
Garanzie ?
Funzionalità di questo strato
Network Layer
4-5
analogia:
Panoramica del Layer 3
Host, router network layer functions:
Network Layer
4-6
forwarding
table
Protocolli di routing
IP protocol
ICMP protocol
Livello trasporto: TCP, UDP
Livello Data Link
Livello Fisico
Network
layer
↑ Control plane
Data plane🡪
Funzioni di un router
Network Layer
4-7
Network Layer
4-8
Code di input
Routing decentrato:
Network Layer
4-9
Livello fisico:
ricezione di bit
Livello data-line:
es. Ethernet,
collegamento
diretto PPP
Code di output
Network Layer
4-10
Perchè le perdite di pacchetti?
Network Layer
4-11
Formato di un datagramma
Network Layer
4-12
ver
length
32 bits
DATI
(lunghezza variab.,
tipicamente un
pacchetto TCP
o UDP)
16-bit identifier
Internet
checksum
time to
live
32 bit source IP address
Numero di versione
lunghezza intestazione
(bytes)
numero massimo
di hops attraversabili
(diminuito di 1 a� ogni salto)
per
gestire la
frammentazione
Lung. totale
datagramma
(bytes)
codice del protocollo�di liv. superiore veicolato
head.
len
type of
service
“tipo” dei dati
flgs
fragment
offset
upper
layer
32 bit destination IP address
Options (if any)
Es. lista dei
Possibili
routers ecc.
ecc.
Quanto overhead con TCP/IP?
Frammentazione
Network Layer
4-13
frammentazione:
in: 1 datagramma grande
out: 3 datagrammi piccoli
reassembly
Riassemblaggio
Network Layer
4-14
ID
=x
offset
=0
fragflag
=0
length
=4000
ID
=x
offset
=0
fragflag
=1
length
=1500
ID
=x
offset
=185
fragflag
=1
length
=1500
ID
=x
offset
=370
fragflag
=0
length
=1060
Spezzettato!
Esempio
1480 bytes in �data field
offset =
1480/8
Indirizzamento
Network Layer
4-15
223.1.1.1
223.1.1.2
223.1.1.3
223.1.1.4
223.1.2.9
223.1.2.2
223.1.2.1
223.1.3.2
223.1.3.1
223.1.3.27
223.1.1.1 = 11011111 00000001 00000001 00000001
223
1
1
1
Sottoreti
Network Layer
4-16
223.1.1.1
223.1.1.2
223.1.1.3
223.1.1.4
223.1.2.9
223.1.2.2
223.1.2.1
223.1.3.2
223.1.3.1
223.1.3.27
network consisting of 3 subnets
subnet
Sottoreti
Ricetta
Network Layer
4-17
223.1.1.0/24
223.1.2.0/24
223.1.3.0/24
Maschera di
sottorete: /24
Domini di col.
Quanti?
Network Layer
4-18
223.1.1.1
223.1.1.3
223.1.1.4
223.1.2.2
223.1.2.1
223.1.2.6
223.1.3.2
223.1.3.1
223.1.3.27
223.1.1.2
223.1.7.0
223.1.7.1
223.1.8.0
223.1.8.1
223.1.9.1
223.1.9.2
Modalità di assegnazione
CIDR: Classless InterDomain Routing
Network Layer
4-19
11001000 00010111 00010000 00000000
ID di�subnet
numero�host
200.23.16.0/23
Allocazione degli indirizzi
Network Layer
4-20
Assegnazione di subnet IP
Normalmente c’è un ISP (Internet Service Provider) che si occupa di distribuire i numeri alle sue sottoreti
Esempio:
Network Layer
4-21
UNICAL 10100000 01100001 00000000 00000000 160.97.0.0/16
DIMES 10100000 01100001 00011000 00000000 160.97.24.0/24
Matematica 1 10100000 01100001 00101111 00000000 160.97.47.0/24
Matematica 2 10100000 01100001 00111001 00000000 160.97.57.0/25
Labmat 10100000 01100001 00111001 10000000 160.97.57.128/25 …. ...
Indirizzamento gerarchico:�aggregazione per gruppi di indirizzi
Network Layer
4-22
Riceve tutto quello
che inizia per
200.23.16.0/20
200.23.16.0/23
200.23.18.0/23
200.23.30.0/23
Fly-By-Night-ISP
Organization 0
Organization 7
Internet
Organization 1
ISPs-R-Us
Riceve tutto
quello che inizia per
199.31.0.0/16
200.23.20.0/23
Organization 2
.
.
.
.
.
.
Le tabelle di forwarding non hanno un rigo per ogni IP, ma per ogni
sottorete: questo consente una più efficiente gestione delle tabelle
Indirizzamento
D: Ma come fa un ISP ad avere degli indirizzi?
R: ICANN: Internet Corporation for Assigned
Names and Numbers
Network Layer
4-23
DHCP
Network Layer
4-24
Come farsi assegnare un indirizzo IP?
Network Layer
4-25
DHCP: Dynamic Host Configuration Protocol
Network Layer: 4-26
goal: host dynamically obtains IP address from network server when it “joins” network
DHCP overview:
DHCP client-server scenario
Network Layer: 4-27
223.1.1.1
223.1.1.2
223.1.1.3
223.1.1.4
223.1.2.9
223.1.2.2
223.1.2.1
223.1.3.2
223.1.3.1
223.1.3.27
DHCP server
223.1.2.5
arriving DHCP client needs
address in this network
Typically, DHCP server will be co-located in router, serving all subnets to which router is attached
DHCP client-server scenario
Network Layer: 4-28
DHCP server: 223.1.2.5
Arriving client
DHCP discover
src : 0.0.0.0, 68
dest.: 255.255.255.255,67
yiaddr: 0.0.0.0
transaction ID: 654
DHCP offer
src: 223.1.2.5, 67
dest: 255.255.255.255, 68
yiaddrr: 223.1.2.4
transaction ID: 654
lifetime: 3600 secs
DHCP request
src: 0.0.0.0, 68
dest:: 255.255.255.255, 67
yiaddrr: 223.1.2.4
transaction ID: 655
lifetime: 3600 secs
DHCP ACK
src: 223.1.2.5, 67
dest: 255.255.255.255, 68
yiaddrr: 223.1.2.4
transaction ID: 655
lifetime: 3600 secs
Broadcast: is there a DHCP server out there?
Broadcast: I’m a DHCP server! Here’s an IP address you can use
Broadcast: OK. I would like to use this IP address!
Broadcast: OK. You’ve got that IP address!
The two steps above can be skipped “if a client remembers and wishes to reuse a previously allocated network address” [RFC 2131]
ICMP
Network Layer
4-29
NETWORK ADDRESS TRANSLATION - NAT
Network Layer
4-30
Alcuni fatti
Network Layer
4-31
NAT: Network Address Translation
Network Layer
4-32
10.0.0.1
10.0.0.2
10.0.0.3
10.0.0.4
138.76.29.7
rete locale
(es., rete casalinga)
10.0.0.0/24
resto�di Internet
Internamente i datagrammi
vengono scambiati usando gli
indirizzi locali
del tipo 10.0.0.0/24
Il router RISCRIVE i pacchetti!
Tutti i datagrammi in uscita dalla
rete locale hanno lo stesso indirizzo sorgente NAT: 138.76.29.7,
ma possono avere numeri di
porta sorgente differenti
NAT: Network Address Translation
Network Layer
4-33
NAT: Network Address Translation
Network Layer
4-34
10.0.0.1
10.0.0.2
10.0.0.3
S: 10.0.0.1, 3345
D: 128.119.40.186, 80
1
10.0.0.4
138.76.29.7
1: l’host 10.0.0.1
manda datagramma a
128.119.40.186, 80
NAT translation table
WAN side addr LAN side addr
138.76.29.7, 5001 10.0.0.1, 3345
…… ……
S: 128.119.40.186, 80
D: 10.0.0.1, 3345
4
S: 138.76.29.7, 5001
D: 128.119.40.186, 80
2
2: Il router NAT
cambia i datagrammi
uscenti da
10.0.0.1, 3345 a
138.76.29.7, 5001,
e aggiorna la tabella
S: 128.119.40.186, 80
D: 138.76.29.7, 5001
3
3: Arriva risposta
destinata a:
138.76.29.7, 5001
4: Il router NAT cambia
l’indirizzo e porta di destinazione
138.76.29.7, 5001 to 10.0.0.1, 3345
NAT: Network Address Translation
Implementazione: Un router NAT deve:�
i client remoti rispondono credendo di avere a che fare con una connessione aperta su
(Indirizzo router NAT, nuovo num. di porta)
ogni coppia (indirizzo interno, porta) <->(nuova porta) �
(Indirizzo router NAT, nuova porta) nei campi destinazione in base alla tabella di traduzione
Network Layer
4-35
NAT: Network Address Translation
Network Layer
4-36
Port Forwarding
Network Layer
4-37
10.0.0.1
10.0.0.2
10.0.0.3
S: 10.0.0.1, 80
D: 128.119.40.186,501
3
10.0.0.4
138.76.29.7
3: l’host 10.0.0.1
manda datagramma a
128.119.40.186, 501
NAT forwarding table
WAN side addr LAN side addr
138.76.29.7, 80 10.0.0.1, 80
…… ……
S: 128.119.40.186, 501
D: 10.0.0.1, 80
2
S: 138.76.29.7, 80
D: 128.119.40.186, 501
4
4: Il router NAT
cambia i datagrammi
uscenti da
10.0.0.1, 80 a
138.76.29.7, 80
S: 128.119.40.186, 501
D: 138.76.29.7, 80
1
1: Arriva richiesta
destinata a:
138.76.29.7, 80
2: Il router NAT cambia
l’INDIRIZZO di destinazione
138.76.29.7 a 10.0.0.1
Questa tabella è fissata manualmente. Il server interno deve avere IP FISSATO.
Port forwarding
Network Layer
4-38
Chain PREROUTING �target prot opt source destination
DNAT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80 to:192.168.0.10
NAT e connessioni P2P
Network Layer
4-39
Indirizzi Broadcast e altri indirizzi speciali
Network Layer
4-40
ICMP
41
ALCUNI PROBLEMI DI SICUREZZA
Network Layer
4-42
Alcune minacce
Network Layer
4-43
Aggressore
IP falso: 192.168.0.1
Rete
Vittima
IP: 192.168.0.1
Ignari host della
sottorete
Alcune minacce
Network Layer
4-44
Vittima
192.168.0.1
Aggressore
192.168.0.2
Dati per 192.168.0.1
Dati da 192.168.0.2
(ma apparentemente da 192.168.0.1)
Dati per 192.168.0.1
(modificati)
Dati da 192.168.0.2
(ma apparentemente da 192.168.0.1)