Skip to content

Commit 72298ba

Browse files
committed
Merge remote-tracking branch 'bernard/master'
2 parents 1f2a6e3 + 7e11b8e commit 72298ba

File tree

6 files changed

+64
-14
lines changed

6 files changed

+64
-14
lines changed

components/dfs/src/dfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,11 @@ int fd_is_open(const char *pathname)
234234
mountpath = fullpath + strlen(fs->path);
235235

236236
dfs_lock();
237+
#ifdef DFS_USING_STDIO
238+
for (index = 3; index < DFS_FD_MAX+3; index++)
239+
#else
237240
for (index = 0; index < DFS_FD_MAX; index++)
241+
#endif
238242
{
239243
fd = &(fd_table[index]);
240244
if (fd->fs == RT_NULL)

components/drivers/src/ringbuffer.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb,
100100
const rt_uint8_t *ptr,
101101
rt_uint16_t length)
102102
{
103-
enum rt_ringbuffer_state old_state;
103+
rt_uint16_t space_length;
104104

105105
RT_ASSERT(rb != RT_NULL);
106106

107-
old_state = rt_ringbuffer_status(rb);
107+
space_length = rt_ringbuffer_space_len(rb);
108108

109-
if (length > rb->buffer_size)
109+
if (length > space_length)
110110
length = rb->buffer_size;
111111

112112
if (rb->buffer_size - rb->write_index > length)
@@ -117,7 +117,7 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb,
117117
* length of data in current mirror */
118118
rb->write_index += length;
119119

120-
if (old_state == RT_RINGBUFFER_FULL)
120+
if (length > space_length)
121121
rb->read_index = rb->write_index;
122122

123123
return length;
@@ -134,7 +134,7 @@ rt_size_t rt_ringbuffer_put_force(struct rt_ringbuffer *rb,
134134
rb->write_mirror = ~rb->write_mirror;
135135
rb->write_index = length - (rb->buffer_size - rb->write_index);
136136

137-
if (old_state == RT_RINGBUFFER_FULL)
137+
if (length > space_length)
138138
{
139139
rb->read_mirror = ~rb->read_mirror;
140140
rb->read_index = rb->write_index;

components/net/lwip-1.4.1/src/core/ipv4/ip.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,11 @@ ip_input(struct pbuf *p, struct netif *inp)
312312
int check_ip_src=1;
313313
#endif /* IP_ACCEPT_LINK_LAYER_ADDRESSING */
314314

315+
#if IP_NAT
316+
extern u8_t ip_nat_input(struct pbuf *p);
317+
extern u8_t ip_nat_out(struct pbuf *p);
318+
#endif
319+
315320
IP_STATS_INC(ip.recv);
316321
snmp_inc_ipinreceives();
317322

@@ -487,15 +492,30 @@ ip_input(struct pbuf *p, struct netif *inp)
487492

488493
/* packet not for us? */
489494
if (netif == NULL) {
495+
#if IP_FORWARD || IP_NAT
496+
u8_t taken = 0;
497+
#endif /* IP_FORWARD || IP_NAT */
490498
/* packet not for us, route or discard */
491499
LWIP_DEBUGF(IP_DEBUG | LWIP_DBG_TRACE, ("ip_input: packet not for us.\n"));
492-
#if IP_FORWARD
500+
#if IP_FORWARD || IP_NAT
493501
/* non-broadcast packet? */
494-
if (!ip_addr_isbroadcast(&current_iphdr_dest, inp)) {
495-
/* try to forward IP packet on (other) interfaces */
496-
ip_forward(p, iphdr, inp);
497-
} else
502+
if (!ip_addr_isbroadcast(&(iphdr->dest), inp)) {
503+
#if IP_NAT
504+
/* check if we want to perform NAT with this packet. */
505+
taken = ip_nat_out(p);
506+
if (!taken)
507+
#endif /* IP_NAT */
508+
{
509+
#if IP_FORWARD
510+
/* try to forward IP packet on (other) interfaces */
511+
if (ip_forward(p, iphdr, inp) != NULL) {
512+
taken = 1;
513+
}
498514
#endif /* IP_FORWARD */
515+
}
516+
}
517+
if (!taken)
518+
#endif /* IP_FORWARD || IP_NAT */
499519
{
500520
snmp_inc_ipinaddrerrors();
501521
snmp_inc_ipindiscards();
@@ -553,6 +573,13 @@ ip_input(struct pbuf *p, struct netif *inp)
553573
current_netif = inp;
554574
current_header = iphdr;
555575

576+
#if IP_NAT
577+
if (!ip_addr_isbroadcast(&(iphdr->dest), inp) &&
578+
(ip_nat_input(p) != 0)) {
579+
LWIP_DEBUGF(IP_DEBUG, ("ip_input: packet consumed by nat layer\n"));
580+
} else
581+
#endif /* IP_NAT */
582+
556583
#if LWIP_RAW
557584
/* raw input did not eat the packet? */
558585
if (raw_input(p, inp) == 0)

components/net/lwip_nat/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
lwIP NAT componenent
2+
3+
If you want to use lwIP NAT componenent, please define LWIP_USING_NAT in rtconfig.h.
4+
5+
In this case the network 213.129.231.168/29 is nat'ed when packets are sent to the
6+
destination network 10.0.0.0/24 (untypical example - most users will have the other
7+
way around).
8+
9+
Use following code to add a NAT entry:
10+
11+
ip_nat_entry_t nat_entry;
12+
13+
nat_entry.out_if = (struct netif *)&emac_if1;
14+
nat_entry.in_if = (struct netif *)&emac_if2;
15+
IP4_ADDR(&nat_entry.source_net, 213, 129, 231, 168);
16+
IP4_ADDR(&nat_entry.source_netmask, 255, 255, 255, 248);
17+
IP4_ADDR(&nat_entry.dest_net, 10, 0, 0, 0);
18+
IP4_ADDR(&nat_entry.source_netmask, 255, 0, 0, 0);
19+
ip_nat_add(&_nat_entry);

components/net/lwip_nat/ipv4_nat.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -435,16 +435,16 @@ ip_nat_check_header(struct pbuf *p, u16_t min_size)
435435
* @return 1 if the packet has been consumed (it was a NAT packet),
436436
* 0 if the packet has not been consumed (no NAT packet)
437437
*/
438-
int
439-
ip_nat_input(struct pbuf *p, struct netif *inp)
438+
u8_t
439+
ip_nat_input(struct pbuf *p)
440440
{
441441
struct ip_hdr *iphdr = (struct ip_hdr*)p->payload;
442442
struct tcp_hdr *tcphdr;
443443
struct udp_hdr *udphdr;
444444
struct icmp_echo_hdr *icmphdr;
445445
nat_entry_t nat_entry;
446446
err_t err;
447-
int consumed = 0;
447+
u8_t consumed = 0;
448448
int i;
449449
struct pbuf *q = NULL;
450450

components/net/lwip_nat/ipv4_nat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ typedef struct ip_nat_entry
8888

8989
void ip_nat_init(void);
9090
void ip_nat_tmr(void);
91-
int ip_nat_input(struct pbuf *p, struct netif *inp);
91+
u8_t ip_nat_input(struct pbuf *p);
9292
u8_t ip_nat_out(struct pbuf *p);
9393

9494
err_t ip_nat_add(const ip_nat_entry_t *new_entry);

0 commit comments

Comments
 (0)