Re: [lwip-users] Packet queuing to an ARP table entry

2017-11-14 Thread goldsi...@gmx.de

Amena El Homsi wrote:

I am trying to send ping request using Lwip.
The ICMP header and ping data is in my system frame memory referenced 
by a PBUF_ROM 'p' (p->payload points to the ICMP hdr in the frame memory.


Is this correct? How long is the contents of this buffer stable? 
PBUF_ROM means ROM - i.e. stable for very long, not just until you think 
normal transmission is done. This is *not* very common!


The PBUF_ROM is chained by a PBUF_RAM 'q' in which the ETHERNET and IP 
headers are saved

[..]
When I tried to send the first ping, LwIP sends an ARP request and 
queue the packet. The problem is that LwIP creates a new pbuf RAM 'r' 
and copies 'q' of type PBUF RAM and 'p' of type PBUF_ROM to the new 
PBUF RAM!


I guess it's like that since your case is just very uncommon. Noone has 
ever bothered to improve for this. Normally, even if you have PBUF_ROM 
pbufs at some point, they are not the first frames sent to some devices. 
Plus it's normally not worth to improve for not copying here.


Indeed I don't want to copy PBUF_ROM payload to the new PBUF_RAM, is 
there a way to avoid such copy? why LwIP doesn't copy 'q' to 'r' while 
preserving the chain between the PBUF_RAM and PBUF_ROM?


Now this might work for the special case where the last pbuf(s) in a 
chain are ROM (remember we need to copy all non-ROM pbufs). We could of 
course create a new ROM pbuf referencing the same data, which would 
prevent copying.


May I ask why it's worth making this change? I.e. does it really hurt 
performance or memory constraints in your case?



Simon

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] lwip stats tcp cachehit

2017-11-14 Thread goldsi...@gmx.de

Markus Pischinger wrote:

what does the "cachehit" in tcp stats refer to?


It just means that the input pcb (active or listening) was the first in 
the list. Not too interesting...


I got some "proterr" aswell but as far as i've seen they occur when i 
get a packet while not having an active connection, is that correct?


Yes.

Simon

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


[lwip-users] Packet queuing to an ARP table entry

2017-11-14 Thread Amena El Homsi
Hi,
I am using lwip 2.0.3 Release version.

I am trying to send ping request using Lwip.
The ICMP header and ping data is in my system frame memory referenced by a
PBUF_ROM 'p' (p->payload points to the ICMP hdr in the frame memory.

The PBUF_ROM is chained by a PBUF_RAM 'q' in which the ETHERNET and IP
headers are saved

q: q->next = p  p:
p->next = NULL
q->payload = q + sizeof(struct pbuf)p->payload
= memory address
q->len = Eth hdr size + IP hdr size  p->len =
ICMP hdr size + ping data size
q->tot_len = q->len + p->len
p->tot_len = p->len
q->type = PBUF_RAM p->type
= PBUF_ROM

When I tried to send the first ping, LwIP sends an ARP request and queue
the packet. The problem is that LwIP creates a new pbuf RAM 'r' and copies
'q' of type PBUF RAM and 'p' of type PBUF_ROM to the new PBUF RAM!
Indeed I don't want to copy PBUF_ROM payload to the new PBUF_RAM, is there
a way to avoid such copy? why LwIP doesn't copy 'q' to 'r' while preserving
the chain between the PBUF_RAM and PBUF_ROM?

Regards,
Amena

-- 

Amena El-Homsi
Computer & Communication Engineer
Dipl. Eng,  M.S.
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] httpd: how to implement AJAX

2017-11-14 Thread Giuseppe Modugno

Il 14/11/2017 13:54, Noam Weissman ha scritto:

Hi,

HTTPD is widely used and if you look around you can find examples from ST micro 
TI and other vendors.
Do you mean HTTPD *without* a secure layer? Yes, I know there are many 
examples of it, but IMHO because it is simpler than a full HTTPS server.
I don't think you can use a non-secure HTTP (or MQTT or SNMP) 
communication in a public network today for a serious application that 
isn't a simple test example.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

Re: [lwip-users] httpd: how to implement AJAX

2017-11-14 Thread Noam Weissman
Hi,

HTTPD is widely used and if you look around you can find examples from ST micro 
TI and other vendors.

The examples that you will find are probably older versions with no POST or 
AJAX  support but they work !

Noam.
 
-Original Message-
From: lwip-users [mailto:lwip-users-bounces+noam=silrd@nongnu.org] On 
Behalf Of Giuseppe Modugno
Sent: Tuesday, November 14, 2017 2:47 PM
To: lwip-users@nongnu.org
Subject: Re: [lwip-users] httpd: how to implement AJAX

Il 13/11/2017 21:25, goldsi...@gmx.de ha scritto:
> Giuseppe Modugno wrote:
>> The prototype for SSI callbacks is:
>> [..]
>> I don't see any reference to query string parameters. So how to 
>> select the right action?
>
> Sorry for the confusion. This is a mix of resource optimization, 
> missing documentation and maybe missing framework functions.
Thank you very much for your explanation. Now it is clear.

> My plan is to have https examples for the next release...
https would be very interesting (actually a simple non-secure http server isn't 
really useable in public Internet).

If I understood correctly, https means ssl/tls. So the first task is to add 
SSL/TLS to lwip, right? It's a pity lwip doesn't feature those secure network 
layers.

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] httpd: how to implement AJAX

2017-11-14 Thread Noam Weissman
Hi,

Yes I use a different server. My server code was based on a variation of the 
httpd code +
many additions.

I use POST to send the user+password and no it is not encoded... this is mainly 
for simple use.

The SSID is not a cookie... The SSID's are handles in a separate task that does 
the house keeping.

Regarding the single file trick you may be right but this is how it works for 
me and I OK with it :)

Regarding the GET/POST params... as the server parses the URL it also parses 
the GET params.


BR,
Noam.

From: lwip-users [mailto:lwip-users-bounces+noam=silrd@nongnu.org] On 
Behalf Of Giuseppe Modugno
Sent: Tuesday, November 14, 2017 2:42 PM
To: lwip-users@nongnu.org
Subject: Re: [lwip-users] httpd: how to implement AJAX

Il 13/11/2017 18:04, Noam Weissman ha scritto:

Yes SSID is a session ID that had been added to my own server code.
So are you using a completely different HTTP server from the httpd that is in 
apps folder of lwip main source?


When a user askes for a page and there is no ssid the server will redirect 
(send a 303)
And load a login page instead. After the user writes user+password the data is 
sent to
The server.
How do you send user+password to the server? PUT? Do you encode these sensible 
values?


The server call's external code to check for validity of user+pass... if OK it
Request a new ssid from a separate task.

After that the web server sends the previously request page + ssid... every 
operation
at the browser side must add that ssid value.
Is it a cookie, right?


Every time the web server gets a request
with the correct ssid it clears the related timeout. If the ssid timeouts and 
the user asks
for some data it will again redirect to the login page.
Do you call a specific function from main at regular intervals to clear all 
SSID that expire?


Regarding AJAX:

How do you handle SSI ?... I am doing it differently ? I have something like 
this in my code:

const SSI_t SSI_Table[] =
{
  {"mem_rout", mem_routing},
  {"IOSel", IO_Selection},
   {"get_users", get_users},
   {"ajax_reply", AjaxReply},

   {NULL, NULL} // last tag must always be NULL to close the list
};


mem_routing, IO_Selection,  get_users,  and   AjaxReply  are call-back function 
that are called by the web
server as a result of encountering the proper tag... for mem_routing it is   

I think LWIP_HTTPD_CUSTOM_FILES is simpler to use when you have a file that is 
completely dynamic. Your "single tag trick" works, but IMHO is too complex for 
what you have to do.



my AjaxReply parses the GET params and after that does something like that:
How AjaxReply() function could access GET params if they aren't accessible from 
the SSI handler? Most probably the answer is in the file state 
(LWIP_HTTPD_FILE_STATE) that is filled by httpd_cgi_handler() callback (as 
explained by goldsimon).



// get action param
Char *Action = some_function();


If(strcmp(Action, "do_something_1") == 0)
{

}
elses If(strcmp(Action, "do_something_2") == 0)
{

}


else
{
  // print a debug error :  action unknown
}



Hope that helped,
Noam.






From: lwip-users [mailto:lwip-users-bounces+noam=silrd@nongnu.org] On 
Behalf Of Giuseppe Modugno
Sent: Monday, November 13, 2017 6:09 PM
To: lwip-users@nongnu.org
Subject: Re: [lwip-users] httpd: how to implement AJAX

Il 13/11/2017 14:34, Noam Weissman ha scritto:



Hi,



I am using the following technic for AJAX.



Create an empty file named ajax.shtml or ajax.html and add it to your file list.



Inside the file you only write one tag without anything else. For example 




Do not add  CR or LF just the tag !!.



Now when you issue an AJAX call the WEB server opens the file, reads it and 
send its data.

Because the file has only the tag it will parse it, call your handler for that 
tag and send back

To the browser just your data !!
Ok, so you use SSI to create dynamic data. I tried with custom files, because 
*all the content* is dynamic (and not only some parts, defined by specific 
tags).




If you use Juery it will look something like this... actually a function used 
as an event handler in

my own code:



function resetIO()

  {

//Remove the dialog

returnToPage();



$.ajax({

  url: "ajax.shtml",

  dataType : "text",

  type : "GET",

  cache : false,

  data : ({

ssid: ssid,

a: 'opReset',

type: 2

  }),

  error : function()

  {

showMessage("Network Error: Sorry, there was a problem connecting 
to the server.");

  },

  success : function(result)

  {

window.location.href = document.location;

  }

});

  }



In the above data you have the a:  variable,  this is your AJAX action !.
If I understood well, data is translated in query string, in your example:

GET ajax.shtml?ssid=&a=opReset&type=2

Of course,  is the value of

Re: [lwip-users] httpd: how to implement AJAX

2017-11-14 Thread goldsimon


Giuseppe Modugno wrote:
> It's a pity lwip doesn't feature those 
>secure network layers.

Actually, it's not that far away. Have a look at the for master. It's not in 
the releases, yet.

Simon

___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] httpd: how to implement AJAX

2017-11-14 Thread Giuseppe Modugno

Il 13/11/2017 21:25, goldsi...@gmx.de ha scritto:

Giuseppe Modugno wrote:

The prototype for SSI callbacks is:
[..]
I don't see any reference to query string parameters. So how to 
select the right action?


Sorry for the confusion. This is a mix of resource optimization, 
missing documentation and maybe missing framework functions.

Thank you very much for your explanation. Now it is clear.


My plan is to have https examples for the next release...
https would be very interesting (actually a simple non-secure http 
server isn't really useable in public Internet).


If I understood correctly, https means ssl/tls. So the first task is to 
add SSL/TLS to lwip, right? It's a pity lwip doesn't feature those 
secure network layers.


___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users


Re: [lwip-users] httpd: how to implement AJAX

2017-11-14 Thread Giuseppe Modugno

Il 13/11/2017 18:04, Noam Weissman ha scritto:

Yes SSID is a session ID that had been added to my own server code.
So are you using a completely different HTTP server from the httpd that 
is in apps folder of lwip main source?


When a user askes for a page and there is no ssid the server will 
redirect (send a 303)


And load a login page instead. After the user writes user+password the 
data is sent to


The server.

How do you send user+password to the server? PUT? Do you encode these 
sensible values?


The server call’s external code to check for validity of user+pass… if 
OK it


Request a new ssid from a separate task.

After that the web server sends the previously request page + ssid… 
every operation


at the browser side must add that ssid value.


Is it a cookie, right?


Every time the web server gets a request

with the correct ssid it clears the related timeout. If the ssid 
timeouts and the user asks


for some data it will again redirect to the login page.

Do you call a specific function from main at regular intervals to clear 
all SSID that expire?



Regarding AJAX:

How do you handle SSI ?... I am doing it differently ? I have 
something like this in my code:


const SSI_t SSI_Table[] =

{

  {"mem_rout", mem_routing},

  {"IOSel", IO_Selection},

 {"get_users", get_users},

 {"ajax_reply", AjaxReply},

 {NULL, NULL} // last tag must always be NULL to close the list

};

mem_routing, IO_Selection,  get_users,  and   AjaxReply  are call-back 
function that are called by the web


server as a result of encountering the proper tag… for mem_routing it 
is   


I think LWIP_HTTPD_CUSTOM_FILES is simpler to use when you have a file 
that is completely dynamic. Your "single tag trick" works, but IMHO is 
too complex for what you have to do.


my AjaxReply parses the GET params and after that does something like 
that:


How AjaxReply() function could access GET params if they aren't 
accessible from the SSI handler? Most probably the answer is in the file 
state (LWIP_HTTPD_FILE_STATE) that is filled by httpd_cgi_handler() 
callback (as explained by goldsimon).



// get action param

Char *Action = some_function();

If(strcmp(Action, “do_something_1”) == 0)

{

}

elses If(strcmp(Action, “do_something_2”) == 0)

{

}

else

{

// print a debug error :  action unknown

}

Hope that helped,

Noam.

*From:*lwip-users 
[mailto:lwip-users-bounces+noam=silrd@nongnu.org] *On Behalf Of 
*Giuseppe Modugno

*Sent:* Monday, November 13, 2017 6:09 PM
*To:* lwip-users@nongnu.org
*Subject:* Re: [lwip-users] httpd: how to implement AJAX

Il 13/11/2017 14:34, Noam Weissman ha scritto:

Hi,
I am using the following technic for AJAX.
Create an empty file named ajax.shtml or ajax.html and add it to your file list.
Inside the file you only write one tag without anything else. For example 

Do not add  CR or LF just the tag !!.
Now when you issue an AJAX call the WEB server opens the file, reads it and 
send its data.
Because the file has only the tag it will parse it, call your handler for that 
tag and send back
To the browser just your data !!

Ok, so you use SSI to create dynamic data. I tried with custom files, 
because *all the content* is dynamic (and not only some parts, defined 
by specific tags).



If you use Juery it will look something like this... actually a function used 
as an event handler in
my own code:
function resetIO()
   {
     //Remove the dialog
     returnToPage();
 
 $.ajax({

   url: "ajax.shtml",
   dataType : "text",
   type : "GET",
   cache : false,
   data : ({
     ssid: ssid,
     a: 'opReset',
     type: 2
   }),
   error : function()
   {
     showMessage("Network Error: Sorry, there was a problem connecting to 
the server.");
   },
   success : function(result)
   {
     window.location.href = document.location;
   }
     });
   }
In the above data you have the a:  variable,  this is your AJAX action !.

If I understood well, data is translated in query string, in your example:

    GET ajax.shtml?ssid=&a=opReset&type=2

Of course,  is the value of ssid Javascript variable.


In your own SSI/CGI code you have a table with tags + callbacks... one of the 
callback function
Is your AJAX handler. Inside it you create an if <> else layout and handle the 
different actions.

The prototype for SSI callbacks is:

typedef u16_t (*tSSIHandler)(
#if LWIP_HTTPD_SSI_RAW
 const char* ssi_tag_name,
#else /* LWIP_HTTPD_SSI_RAW */
 int iIndex,
#endif /* LWIP_HTTPD_SSI_RAW */
 char *pcInsert, int iInsertLen
#if LWIP_HTTPD_SSI_MULTIPART
 , u16_t current_tag_part, u16_t 
*next_tag_part

#endif /* LWIP_HTTPD_SSI_MULTIPART */
#if defined(LWIP_HTTPD_FILE_STATE) && LWIP_HTTPD_FILE_STATE
   

[lwip-users] lwip stats tcp cachehit

2017-11-14 Thread Markus Pischinger

Hi guys,
what does the "cachehit" in tcp stats refer to?
I just checked my stats got the following:

TCP
      xmit: 58754
      recv: 58877
      fw: 0
      drop: 22
      chkerr: 0
      lenerr: 0
      memerr: 0
      rterr: 0
      proterr: 22
      opterr: 0
      err: 0
      cachehit: 58769

I got some "proterr" aswell but as far as i've seen they occur when i 
get a packet while not having an active connection, is that correct?


Thanks in advance!
Regards,
Markus
___
lwip-users mailing list
lwip-users@nongnu.org
https://lists.nongnu.org/mailman/listinfo/lwip-users