Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
31
Issues
31
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
0b710156
Commit
0b710156
authored
Dec 03, 2018
by
li hongming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Making port0 support ARP/SNMP of port1.
parent
1e846662
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
100 additions
and
79 deletions
+100
-79
arp.c
lib/arp.c
+32
-28
bootp.c
lib/bootp.c
+8
-1
ipv4.c
lib/ipv4.c
+38
-43
cmd_ip.c
shell/cmd_ip.c
+8
-3
pfilter-builder.c
tools/pfilter-builder.c
+14
-4
No files found.
lib/arp.c
View file @
0b710156
...
...
@@ -34,27 +34,25 @@ static void arp_init(void)
// memset(&saddr.mac, 0xFF, 6); /* Broadcast */
saddr
.
ethertype
=
htons
(
0x0806
);
/* ARP */
for
(
port
=
0
;
port
<
wr_num_ports
;
++
port
)
arp_socket
[
port
]
=
ptpd_netif_create_socket
(
&
__static_arp_socket
[
port
],
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
,
port
);
arp_socket
[
port
]
=
ptpd_netif_create_socket
(
&
__static_arp_socket
[
port
],
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
,
port
);
}
static
int
process_arp
(
uint8_t
*
buf
,
int
len
,
int
port
)
static
int
process_arp
(
uint8_t
*
buf
,
int
len
)
{
uint8_t
hisMAC
[
6
];
uint8_t
hisIP
[
4
];
uint8_t
myIP
[
4
];
int
port
=
0
;
uint8_t
myIP
[
2
][
4
];
if
(
len
<
ARP_END
)
return
0
;
/* Is it ARP request targetting our IP? */
getIP
(
myIP
,
port
);
if
(
buf
[
ARP_OPER
+
0
]
!=
0
)
return
0
;
if
(
((
buf
[
ARP_OPER
+
1
]
!=
1
)
||
memcmp
(
buf
+
ARP_TPA
,
myIP
,
4
))
==
0
)
{
if
(
buf
[
ARP_OPER
+
1
]
==
1
)
{
memcpy
(
hisMAC
,
buf
+
ARP_SHA
,
6
);
memcpy
(
hisIP
,
buf
+
ARP_SPA
,
4
);
// ------------- ARP ------------
...
...
@@ -70,14 +68,22 @@ static int process_arp(uint8_t * buf, int len, int port)
// Response
buf
[
ARP_OPER
+
0
]
=
0
;
buf
[
ARP_OPER
+
1
]
=
2
;
// my MAC+IP
get_mac_addr
(
buf
+
ARP_SHA
,
port
);
memcpy
(
buf
+
ARP_SPA
,
myIP
,
4
);
// his MAC+IP
memcpy
(
buf
+
ARP_THA
,
hisMAC
,
6
);
memcpy
(
buf
+
ARP_TPA
,
hisIP
,
4
);
return
ARP_END
;
// my MAC
get_mac_addr
(
buf
+
ARP_SHA
,
0
);
for
(
port
=
0
;
port
<
wr_num_ports
;
++
port
)
{
/* Is it ARP request targetting our IP? */
getIP
(
myIP
[
port
],
port
);
if
(
memcmp
(
buf
+
ARP_TPA
,
myIP
[
port
],
4
)
==
0
)
{
memcpy
(
buf
+
ARP_SPA
,
myIP
[
port
],
4
);
// his MAC+IP
memcpy
(
buf
+
ARP_THA
,
hisMAC
,
6
);
memcpy
(
buf
+
ARP_TPA
,
hisIP
,
4
);
return
ARP_END
;
}
}
}
tcpip_get_hisIP
(
hisIP
);
...
...
@@ -96,21 +102,19 @@ static int arp_poll(void)
uint8_t
buf
[
ARP_END
+
100
];
struct
wr_sockaddr
addr
;
int
len
;
int
port
;
int
port
=
0
;
int
ret
;
if
(
ip_status
==
IP_TRAINING
)
if
(
ip_status
[
port
]
==
IP_TRAINING
)
return
0
;
/* can't do ARP w/o an address... */
ret
=
0
;
for
(
port
=
0
;
port
<
wr_num_ports
;
++
port
)
{
if
((
len
=
ptpd_netif_recvfrom
(
arp_socket
[
port
],
&
addr
,
buf
,
sizeof
(
buf
),
0
,
port
))
>
0
)
{
if
((
len
=
process_arp
(
buf
,
len
,
0
))
>
0
)
ptpd_netif_sendto
(
arp_socket
[
port
],
&
addr
,
buf
,
len
,
0
,
port
);
ret
=
1
;
}
if
((
len
=
ptpd_netif_recvfrom
(
arp_socket
[
port
],
&
addr
,
buf
,
sizeof
(
buf
),
0
,
port
))
>
0
)
{
if
((
len
=
process_arp
(
buf
,
len
))
>
0
)
ptpd_netif_sendto
(
arp_socket
[
port
],
&
addr
,
buf
,
len
,
0
,
port
);
ret
=
1
;
}
return
ret
;
}
...
...
@@ -145,7 +149,7 @@ int send_arp(uint8_t * hisIP, int port)
DEFINE_WRC_TASK
(
arp
)
=
{
.
name
=
"arp"
,
.
enable
=
&
link_status
[
0
]
,
.
enable
=
&
(
link_status
[
0
])
,
.
init
=
arp_init
,
.
job
=
arp_poll
,
};
lib/bootp.c
View file @
0b710156
...
...
@@ -96,7 +96,14 @@ int process_bootp(uint8_t * buf, int len)
setIP
(
buf
+
BOOTP_YIADDR
,
0
);
getIP
(
ip
,
0
);
pp_printf
(
"Discovered IP address (%d.%d.%d.%d)!
\n
"
,
pp_printf
(
"Port 0 Discovered IP address (%d.%d.%d.%d)!
\n
"
,
ip
[
0
],
ip
[
1
],
ip
[
2
],
ip
[
3
]);
// for dualport
ip
[
3
]
=
ip
[
3
]
+
1
;
setIP
(
ip
,
1
);
getIP
(
ip
,
1
);
pp_printf
(
"Port 1 Discovered IP address (%d.%d.%d.%d)!
\n
"
,
ip
[
0
],
ip
[
1
],
ip
[
2
],
ip
[
3
]);
return
1
;
...
...
lib/ipv4.c
View file @
0b710156
...
...
@@ -25,14 +25,12 @@ static uint8_t myIP[2][4];
const
uint8_t
magicUDP
[
4
]
=
{
0x62
,
0x65
,
0x65
,
0x66
};
/* bootp: bigger buffer, UDP based */
static
uint8_t
__bootp_queue
[
2
][
512
];
static
struct
wrpc_socket
__static_bootp_socket
[
2
]
=
{
{.
queue
.
buff
=
__bootp_queue
[
0
],
.
queue
.
size
=
sizeof
(
__bootp_queue
[
0
]),},
{.
queue
.
buff
=
__bootp_queue
[
1
],
.
queue
.
size
=
sizeof
(
__bootp_queue
[
1
]),}
static
uint8_t
__bootp_queue
[
512
];
static
struct
wrpc_socket
__static_bootp_socket
=
{
.
queue
.
buff
=
__bootp_queue
,
.
queue
.
size
=
sizeof
(
__bootp_queue
)
};
static
struct
wrpc_socket
*
bootp_socket
[
2
]
;
static
struct
wrpc_socket
*
bootp_socket
;
/* ICMP: smaller buffer */
static
uint8_t
__icmp_queue
[
2
][
128
];
...
...
@@ -53,12 +51,12 @@ static struct wrpc_socket __static_rdate_socket = {
static
struct
wrpc_socket
*
rdate_socket
;
/* remoteupdate: bigger buffer, UDP based */
static
uint8_t
__r
m
update_queue
[
340
];
static
struct
wrpc_socket
__static_r
m
update_socket
=
{
.
queue
.
buff
=
__r
m
update_queue
,
.
queue
.
size
=
sizeof
(
__r
m
update_queue
),
static
uint8_t
__r
emote_
update_queue
[
340
];
static
struct
wrpc_socket
__static_r
emote_
update_socket
=
{
.
queue
.
buff
=
__r
emote_
update_queue
,
.
queue
.
size
=
sizeof
(
__r
emote_
update_queue
),
};
static
struct
wrpc_socket
*
r
m
update_socket
;
static
struct
wrpc_socket
*
r
emote_
update_socket
;
/* syslog is selected by Kconfig, so we have weak aliases here */
void
__attribute__
((
weak
))
syslog_init
(
void
)
...
...
@@ -85,29 +83,26 @@ unsigned int ipv4_checksum(unsigned short *buf, int shorts)
static
void
ipv4_init
(
void
)
{
struct
wr_sockaddr
saddr
;
int
port
;
int
port
=
0
;
/* Bootp: use UDP engine activated by function arguments */
for
(
port
=
0
;
port
<
wr_num_ports
;
++
port
)
{
bootp_socket
[
port
]
=
ptpd_netif_create_socket
(
&
__static_bootp_socket
[
port
],
NULL
,
PTPD_SOCK_UDP
,
68
/* bootpc */
,
port
);
}
bootp_socket
=
ptpd_netif_create_socket
(
&
__static_bootp_socket
,
NULL
,
PTPD_SOCK_UDP
,
68
/* bootpc */
,
0
);
/* time (rdate): UDP */
rdate_socket
=
ptpd_netif_create_socket
(
&
__static_rdate_socket
,
NULL
,
PTPD_SOCK_UDP
,
37
/* time */
,
0
);
/* remote update (r
m
update): UDP */
r
mupdate_socket
=
ptpd_netif_create_socket
(
&
__static_rm
update_socket
,
NULL
,
/* remote update (r
emote_
update): UDP */
r
emote_update_socket
=
ptpd_netif_create_socket
(
&
__static_remote_
update_socket
,
NULL
,
PTPD_SOCK_UDP
,
71
/* remote update */
,
0
);
/* ICMP: specify raw (not UDP), with IPV4 ethtype */
memset
(
&
saddr
,
0
,
sizeof
(
saddr
));
saddr
.
ethertype
=
htons
(
0x0800
);
for
(
port
=
0
;
port
<
wr_num_ports
;
++
port
)
{
icmp_socket
[
port
]
=
ptpd_netif_create_socket
(
&
__static_icmp_socket
[
port
],
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
,
port
);
}
// All SNMPs go through port 0
icmp_socket
[
0
]
=
ptpd_netif_create_socket
(
&
__static_icmp_socket
[
0
],
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
,
0
);
syslog_init
();
}
...
...
@@ -121,7 +116,7 @@ static int bootp_poll(void)
uint8_t
buf
[
400
];
int
len
,
ret
=
0
;
len
=
ptpd_netif_recvfrom
(
bootp_socket
[
0
]
,
&
addr
,
len
=
ptpd_netif_recvfrom
(
bootp_socket
,
&
addr
,
buf
,
sizeof
(
buf
),
NULL
,
0
);
if
(
ip_status
[
0
]
!=
IP_TRAINING
)
...
...
@@ -134,30 +129,31 @@ static int bootp_poll(void)
return
ret
;
len
=
prepare_bootp
(
&
addr
,
buf
,
++
bootp_retry
);
ptpd_netif_sendto
(
bootp_socket
[
0
]
,
&
addr
,
buf
,
len
,
0
,
0
);
ptpd_netif_sendto
(
bootp_socket
,
&
addr
,
buf
,
len
,
0
,
0
);
return
1
;
}
static
int
icmp_poll
(
int
port
)
static
int
icmp_poll
()
{
struct
wr_sockaddr
addr
;
uint8_t
buf
[
128
];
int
len
;
int
port
=
0
;
len
=
ptpd_netif_recvfrom
(
icmp_socket
[
port
],
&
addr
,
buf
,
sizeof
(
buf
),
NULL
,
port
);
len
=
ptpd_netif_recvfrom
(
icmp_socket
[
0
],
&
addr
,
buf
,
sizeof
(
buf
),
NULL
,
0
);
if
(
len
<=
0
)
return
0
;
if
(
ip_status
[
port
]
==
IP_TRAINING
)
return
0
;
/* check the destination IP */
if
(
check_dest_ip
(
buf
,
port
))
return
0
;
if
((
len
=
process_icmp
(
buf
,
len
,
port
))
>
0
)
ptpd_netif_sendto
(
icmp_socket
[
port
],
&
addr
,
buf
,
len
,
0
,
port
);
return
1
;
for
(
port
=
0
;
port
<
wr_num_ports
;
++
port
)
{
if
(
check_dest_ip
(
buf
,
port
)
==
0
){
if
((
len
=
process_icmp
(
buf
,
len
,
port
))
>
0
)
ptpd_netif_sendto
(
icmp_socket
[
0
],
&
addr
,
buf
,
len
,
0
,
0
);
return
1
;
}
}
return
0
;
}
static
int
rdate_poll
(
void
)
...
...
@@ -189,7 +185,7 @@ static int rdate_poll(void)
return
1
;
}
static
int
r
m
update_poll
(
void
)
static
int
r
emote_
update_poll
(
void
)
{
struct
wr_sockaddr
addr
;
uint8_t
buf
[
512
];
...
...
@@ -200,7 +196,7 @@ static int rmupdate_poll(void)
int
data_size
;
int
port
;
len
=
ptpd_netif_recvfrom
(
r
m
update_socket
,
&
addr
,
len
=
ptpd_netif_recvfrom
(
r
emote_
update_socket
,
&
addr
,
buf
,
sizeof
(
buf
),
NULL
,
0
);
if
(
len
<=
0
)
return
0
;
...
...
@@ -270,7 +266,7 @@ static int rmupdate_poll(void)
}
fill_udp
(
buf
,
len
,
NULL
);
ptpd_netif_sendto
(
rdate_socket
,
&
addr
,
buf
,
len
,
0
,
0
);
ptpd_netif_sendto
(
r
emote_up
date_socket
,
&
addr
,
buf
,
len
,
0
,
0
);
return
1
;
}
...
...
@@ -282,12 +278,11 @@ static int ipv4_poll(void)
ip_status
[
0
]
=
IP_TRAINING
;
ret
=
bootp_poll
();
ret
+=
icmp_poll
(
0
);
ret
+=
icmp_poll
(
1
);
ret
+=
icmp_poll
();
ret
+=
rdate_poll
();
ret
+=
r
m
update_poll
();
ret
+=
r
emote_
update_poll
();
ret
+=
syslog_poll
();
...
...
shell/cmd_ip.c
View file @
0b710156
...
...
@@ -26,13 +26,13 @@ void print_ip(void)
format_ip
(
buf
,
ip
[
port
]);
switch
(
ip_status
[
port
])
{
case
IP_TRAINING
:
pp_printf
(
"
IP-address: in training
\n
"
);
pp_printf
(
"
port %d IP-address: in training
\n
"
,
port
);
break
;
case
IP_OK_BOOTP
:
pp_printf
(
"
IP-address: %s (from bootp)
\n
"
,
buf
);
pp_printf
(
"
port %d IP-address: %s (from bootp)
\n
"
,
port
,
buf
);
break
;
case
IP_OK_STATIC
:
pp_printf
(
"
IP-address: %s (static assignment)
\n
"
,
buf
);
pp_printf
(
"
port %d IP-address: %s (static assignment)
\n
"
,
port
,
buf
);
break
;
}
}
...
...
@@ -74,6 +74,11 @@ static int cmd_ip(const char *args[])
ip_status
[
port
]
=
IP_OK_STATIC
;
decode_ip
(
args
[
1
],
ip
);
setIP
(
ip
,
port
);
if
(
port
==
0
)
{
ip
[
3
]
=
ip
[
3
]
+
1
;
setIP
(
ip
,
1
);
ip_status
[
1
]
=
IP_OK_STATIC
;
}
print_ip
();
}
else
{
return
-
EINVAL
;
...
...
tools/pfilter-builder.c
View file @
0b710156
...
...
@@ -405,12 +405,14 @@ void pfilter_init_novlan(char *fname)
/* Mark one bits for ip-valid (unicast or broadcast) */
pfilter_logic3
(
FRAME_IP_OK
,
FRAME_BROADCAST
,
OR
,
FRAME_MAC_OK
,
AND
,
FRAME_TYPE_IPV4
);
/* check arp for unicast or broadcast */
pfilter_logic3
(
FRAME_TYPE_ARP
,
FRAME_BROADCAST
,
OR
,
FRAME_MAC_OK
,
AND
,
FRAME_TYPE_ARP
);
/* Ethernet = 14 bytes, Offset to type in IP: 8 bytes = 22/2 = 11 */
pfilter_cmp
(
11
,
0x0001
,
0x00ff
,
MOV
,
FRAME_ICMP
);
pfilter_cmp
(
11
,
0x0011
,
0x00ff
,
MOV
,
FRAME_UDP
);
pfilter_logic2
(
FRAME_UDP
,
FRAME_UDP
,
AND
,
FRAME_IP_OK
);
pfilter_cmp
(
11
,
0x0006
,
0x00ff
,
MOV
,
FRAME_TCP
);
pfilter_logic2
(
FRAME_TCP
,
FRAME_TCP
,
AND
,
FRAME_IP_OK
);
/* For CPU: arp or icmp unicast or ptp (or latency) */
pfilter_logic2
(
FRAME_FOR_CPU
,
FRAME_TYPE_ARP
,
OR
,
FRAME_TYPE_PTP2
);
...
...
@@ -424,11 +426,19 @@ void pfilter_init_novlan(char *fname)
pfilter_logic3
(
R_CLASS
(
0
),
FRAME_UDP
,
AND
,
PORT_UDP_HOST
,
OR
,
FRAME_FOR_CPU
);
/* Etherbone is UDP at port 0xebd0, let's "or" in the last move */
pfilter_cmp
(
18
,
0xebd0
,
0xffff
,
MOV
,
PORT_UDP_ETHERBONE
);
//
pfilter_cmp(18, 0xebd0, 0xffff, MOV, PORT_UDP_ETHERBONE);
/* and now copy out fabric selections: 7 etherbone, 6 for anything else */
pfilter_logic2
(
R_CLASS
(
7
),
FRAME_UDP
,
AND
,
PORT_UDP_ETHERBONE
);
pfilter_logic3
(
R_CLASS
(
6
),
FRAME_UDP
,
NAND
,
PORT_UDP_ETHERBONE
,
OR
,
FRAME_TCP
);
// pfilter_logic2(R_CLASS(7), FRAME_UDP, AND, PORT_UDP_ETHERBONE);
// pfilter_logic3(R_CLASS(6), FRAME_UDP, NAND, PORT_UDP_ETHERBONE, OR, FRAME_TCP);
/* other UDP ports marks as class 4 */
pfilter_logic3
(
R_CLASS
(
4
),
PORT_UDP_HOST
,
NOT
,
R_ZERO
,
AND
,
FRAME_UDP
);
/* other TCP ports marks as class 5 */
pfilter_logic2
(
R_CLASS
(
5
),
FRAME_TCP
,
AND
,
FRAME_IP_OK
);
/* mark the broadcast packets as class 7 */
/* which will be transferred to another port */
pfilter_logic2
(
R_CLASS
(
7
),
FRAME_BROADCAST
,
MOV
,
R_ZERO
);
/*
* Note that earlier we used to be more strict in ptp ethtype (only proper multicast),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment