-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
base: master
Are you sure you want to change the base?
Socket ether linux step2 #17926
Conversation
e201885
to
1f1f204
Compare
ext/sockets/sockets.c
Outdated
switch (ip->protocol) { | ||
case IPPROTO_TCP: { | ||
struct tcphdr *tcp = (struct tcphdr *)ipdata; | ||
object_init(&zpayload); |
There was a problem hiding this comment.
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
ext/sockets/sockets.c
Outdated
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)); |
There was a problem hiding this comment.
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;
}
There was a problem hiding this comment.
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
ext/sockets/sockets.c
Outdated
break; | ||
} | ||
case ETH_P_IPV6: { | ||
payload = ((unsigned char *)e + sizeof(struct ethhdr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
payload = ((unsigned char *)e + sizeof(struct ethhdr)); | |
payload = ((unsigned char *)e + ETH_HLEN); |
ext/sockets/sockets.c
Outdated
|
||
switch (protocol) { | ||
case ETH_P_IP: { | ||
payload = ((unsigned char *)e + sizeof(struct ethhdr)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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
ext/sockets/sockets.c
Outdated
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); |
There was a problem hiding this comment.
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
ext/sockets/sockets.c
Outdated
} | ||
case ETH_P_LOOP: { | ||
struct ethhdr *innere = (struct ethhdr *)((unsigned char *)e + ETH_HLEN); | ||
object_init(&zpayload); |
There was a problem hiding this comment.
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
ext/sockets/sockets.stub.php
Outdated
/** @readonly **/ | ||
public string $rawpayload; | ||
/** @readonly **/ | ||
public ?object $payload; |
There was a problem hiding this comment.
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
.
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. |
Back to the drawing board due to UAF with previous version. This reverts commit cc11606.
2930c13
to
3b96b21
Compare
9e8daaa
to
8cd42ca
Compare
No description provided.