Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket ether linux step2 #17926

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

devnexen
Copy link
Member

No description provided.

@devnexen devnexen force-pushed the socket_ether_linux_step2 branch 2 times, most recently from e201885 to 1f1f204 Compare February 26, 2025 21:09
@devnexen devnexen marked this pull request as ready for review February 26, 2025 21:46
@devnexen devnexen requested a review from kocsismate as a code owner February 26, 2025 21:46
@devnexen devnexen requested a review from arnaud-lb February 26, 2025 21:46
switch (ip->protocol) {
case IPPROTO_TCP: {
struct tcphdr *tcp = (struct tcphdr *)ipdata;
object_init(&zpayload);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use a class, e.g. TcpPacket

Comment on lines 1684 to 1685
zend_update_property_string(Z_OBJCE(zpayload), Z_OBJ(zpayload), ZEND_STRL("ipsrc"), inet_ntoa(s));
zend_update_property_string(Z_OBJCE(zpayload), Z_OBJ(zpayload), ZEND_STRL("ipdst"), inet_ntoa(d));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This belongs to the IP layer, and should be in a separate object:

final readonly class SocketEthernetInfo // or EthernetPacket ?
{
    public Socket $socket;
    public int    $protocol;
    public string $macsrc;
    public string $macdst;

    public Ipv4Packet|Ipv6Packet|null $payload;

    public int $headersize;
    public string $rawpacket;
}

final readonly class Ipv4Packet
{
    public string $srcaddr;
    public string $dscaddr;
    // ... (other fields)

    public ?object $payload;

    public int $headersize;
    public string $rawpacket;
}

final readonly class TcpPacket
{
    public string $srcport;
    public string $dstport;
    // ...

    public int $headersize;
    public string $rawpacket;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: We should probably namespace those

break;
}
case ETH_P_IPV6: {
payload = ((unsigned char *)e + sizeof(struct ethhdr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
payload = ((unsigned char *)e + sizeof(struct ethhdr));
payload = ((unsigned char *)e + ETH_HLEN);


switch (protocol) {
case ETH_P_IP: {
payload = ((unsigned char *)e + sizeof(struct ethhdr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
payload = ((unsigned char *)e + sizeof(struct ethhdr));
payload = ((unsigned char *)e + ETH_HLEN);

case ETH_P_IP: {
payload = ((unsigned char *)e + sizeof(struct ethhdr));
struct iphdr *ip = (struct iphdr *)payload;
unsigned char *ipdata = payload + (ip->ihl * 4);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not trust ip->ihl

Comment on lines 1721 to 1760
object_init(&zpayload);
zend_update_property_string(Z_OBJCE(zpayload), Z_OBJ(zpayload), ZEND_STRL("ipsrc"), s);
zend_update_property_string(Z_OBJCE(zpayload), Z_OBJ(zpayload), ZEND_STRL("ipdst"), d);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could expose the payload here, like we do for ETH_P_IP

}
case ETH_P_LOOP: {
struct ethhdr *innere = (struct ethhdr *)((unsigned char *)e + ETH_HLEN);
object_init(&zpayload);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a SocketEthernetInfo

Comment on lines 2176 to 2179
/** @readonly **/
public string $rawpayload;
/** @readonly **/
public ?object $payload;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested this, but I think that rawpayload is not the right name after all. The payload field represents the contents of the eth packet, but the rawpayload field represents the eth packet itself. rawpacket would be a better name than rawpayload.

@devnexen devnexen marked this pull request as draft February 27, 2025 12:16
@devnexen devnexen marked this pull request as ready for review February 27, 2025 21:28
@bukka
Copy link
Member

bukka commented Mar 3, 2025

This has a bit of class design so it should be probably at least posted to internals (it's not like adding a constant or a simple funciton). I agree that there should be some namespacing as well possibly. Definitely not the current names that will easily result in BC break for appliations.

@devnexen devnexen marked this pull request as draft March 7, 2025 19:52
@devnexen devnexen force-pushed the socket_ether_linux_step2 branch from 2930c13 to 3b96b21 Compare March 7, 2025 19:53
@devnexen devnexen force-pushed the socket_ether_linux_step2 branch from 9e8daaa to 8cd42ca Compare March 7, 2025 22:29
@devnexen devnexen marked this pull request as ready for review March 8, 2025 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants