Beruflich Dokumente
Kultur Dokumente
TCP / IP
vs.
Process
Socket layer
OSI model
7: Application
6: Presentation
5: Session
4: Transport
3: Network
2: Data
Link
1: Physical
Layer
1: sosend (... )
5: recvfrom(.)
Socket Layer
2: tcp_output ( . )
4: tcp_input ( ... )
3: ip_output ( . )
3: ip_input ( ... )
4: ethernet_output ( . )
2: ethernet_input ( .. )
Interface Layer (Ethernet Device Driver)
Physical Media
Output Queue
Input Queue
Process Layer
to
TCP Layer
send (int socket, const char *buf, int length, int flags)
Process
Kernel
sendto (int socket, const char *data_buffer, int length, int flags, struct sockaddr *destination, int destination _length)
sendit (struct proc *p, int socket, struct msghdr *mp, int flags, int *return_size)
sosend (struct socket *s, struct mbuf *addr, struct uio *uio, struct mbuf *top, struct mbuf *control, int flags )
tcp_userreq (struct socket *s, int request, struct mbuf *m, struct mbuf * nam, struct mbuf * control )
TCP Layer
uipc_syscalls.c
uipc_socket.c
tcp_userreq.c
tcp_output.c
Socket Layer
sendto (int socket, const char *data_buffer, int length, int flags, struct sockaddr *destination, int destination _length)
MBUF Chain
m_next = NULL
m_next
28 Bytes
m_nextpkt = NULL
m_nextpkt = NULL
m_len = 100
m_len = 50
m_data
20 Bytes
m_type = MT_DATA
m_type = MT_DATA
data_buffer
m_flags = M_PKTHDR
m_flags = 0
m_pkthdr.len = 150
128 Bytes
mBuf
150 Bytes
Data
m_data
m_pkthdr.recvif =NULL
100 Bytes
50 Bytes
Data
58 Bytes
Unused Space
Data
Socket Layer -sosend passes data and control information to the protocol layer
sosend(struct socket *s, struct mbuf *addr, struct uio *uio, struct mbuf *data_buffer, struct mbuf *control, int flags )
no
Is there enough space
in the buffer
sbspace(s->sb_snd)
yes
Copy data_buffer
mbuf
More buffers
to send?
1
error
no
TCP Layer - tcp_usrreq(struct socket *s, int request, struct mbuf *data_buffer, mbuf *nam, mbuf * control)
Initialize internet protocol control block inp and
TCP control block tp
to store information useful for TCP
Convert Socket to
Internet Protocol Control Block
inp = sotoinpcb(so)
request
PRU_SEND
int error = tcp_output(tp)
return error
to tcp_userreq( )
true
Send acknowledgement
false
true
false
false
true
Finished sending
Allocate an mbuf for the TCP & IP header and data if possible.
MGETHDR ( m, M_DONTWAIT, MT_HEADR)
M_DONTWAIT indicates that if memory is not available for
mbuf then come out of the routine and return an error state.
no
yes
Copy the data from the socket send buffer into the
new packet header mbuf
ip_output.c
ip_output(struct mbuf *m, struct mbuf *opt, struct route *ro, int flags, struct ip_moptions *imo)
1. Header initialization
2. Route Selection
3. Source address selection and Fragmentation
1. Header initialization
Packets
damaged?
ERROR
yes
no
if ((flags == IP_FORWARDING ) ||
(flags == IP_RAWOUTPUT ))
yes
no
2. Route Selection
If (cached_route == destination)
no
yes
no
yes
yes
no
1. Verification
Ethernet port
up and running ?
ifp -> if_flags &
(IF_UP | IF_RUNNING )
yes
no
senderr (ENETDOWN)
yes
no
senderr (ENETDOWN)
0
Route valid ?
rt_entry = rtalloc1 (destination, 1)
senderr (EHOSTUNREACH)
1
Destination responding
to ARP requests?
If not then do not send more
packets to avoid flooding.
rt -> rt_flags &
RTF_REJECT
no
Verification
AF_INET
Frame Preparartion
Frame Preparartion
Make sure there is room for the 14 byte
ethernet header
M_PREPEND ( m, sizeof(ethernet_header),
M_DONOTWAIT)
Frame Preparartion
Interface Queuing
yes
Is the output queue full
no
lestart ( ifp )
if_snd
lestart ( ifp )
0
le -> sc_if.if_flags &
IFF_RUNNING
1
Copy the the frame in mbuf to the
hardware buffer
return error