mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:57:36 +00:00
Kernel: Support ioctl SIOCSARP and SIOCDARP
Creates ioctl calls necessary to set/delete an entry from the ARP table
This commit is contained in:
parent
f8c104aaaf
commit
8313d35749
4 changed files with 50 additions and 0 deletions
|
@ -604,6 +604,32 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, FlatPtr arg)
|
|||
return -EINVAL;
|
||||
};
|
||||
|
||||
auto ioctl_arp = [request, arg]() {
|
||||
arpreq arp_req;
|
||||
if (!copy_from_user(&arp_req, (arpreq*)arg))
|
||||
return -EFAULT;
|
||||
|
||||
switch (request) {
|
||||
case SIOCSARP:
|
||||
if (!Process::current()->is_superuser())
|
||||
return -EPERM;
|
||||
if (arp_req.arp_pa.sa_family != AF_INET)
|
||||
return -EAFNOSUPPORT;
|
||||
update_arp_table(IPv4Address(((sockaddr_in&)arp_req.arp_pa).sin_addr.s_addr), *(MACAddress*)&arp_req.arp_ha.sa_data[0], UpdateArp::Set);
|
||||
return 0;
|
||||
|
||||
case SIOCDARP:
|
||||
if (!Process::current()->is_superuser())
|
||||
return -EPERM;
|
||||
if (arp_req.arp_pa.sa_family != AF_INET)
|
||||
return -EAFNOSUPPORT;
|
||||
update_arp_table(IPv4Address(((sockaddr_in&)arp_req.arp_pa).sin_addr.s_addr), *(MACAddress*)&arp_req.arp_ha.sa_data[0], UpdateArp::Delete);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
};
|
||||
|
||||
auto ioctl_interface = [request, arg]() {
|
||||
ifreq* user_ifr = (ifreq*)arg;
|
||||
ifreq ifr;
|
||||
|
@ -730,6 +756,10 @@ int IPv4Socket::ioctl(FileDescription&, unsigned request, FlatPtr arg)
|
|||
case SIOCADDRT:
|
||||
case SIOCDELRT:
|
||||
return ioctl_route();
|
||||
|
||||
case SIOCSARP:
|
||||
case SIOCDARP:
|
||||
return ioctl_arp();
|
||||
}
|
||||
|
||||
return -EINVAL;
|
||||
|
|
|
@ -691,6 +691,14 @@ struct rtentry {
|
|||
#define AT_FDCWD -100
|
||||
#define AT_SYMLINK_NOFOLLOW 0x100
|
||||
|
||||
struct arpreq {
|
||||
struct sockaddr arp_pa; /* protocol address */
|
||||
struct sockaddr arp_ha; /* hardware address */
|
||||
struct sockaddr arp_netmask; /* netmask of protocol address */
|
||||
int arp_flags; /* flags */
|
||||
char arp_dev[16];
|
||||
};
|
||||
|
||||
#define PURGE_ALL_VOLATILE 0x1
|
||||
#define PURGE_ALL_CLEAN_INODE 0x2
|
||||
|
||||
|
|
|
@ -18,3 +18,11 @@ struct rtentry {
|
|||
|
||||
#define RTF_UP 0x1 /* do not delete the route */
|
||||
#define RTF_GATEWAY 0x2 /* the route is a gateway and not an end host */
|
||||
|
||||
struct arpreq {
|
||||
struct sockaddr arp_pa; /* protocol address */
|
||||
struct sockaddr arp_ha; /* hardware address */
|
||||
struct sockaddr arp_netmask; /* netmask of protocol address */
|
||||
int arp_flags; /* flags */
|
||||
char arp_dev[16];
|
||||
};
|
||||
|
|
|
@ -79,6 +79,8 @@ enum IOCtlNumber {
|
|||
SIOCGIFCONF,
|
||||
SIOCADDRT,
|
||||
SIOCDELRT,
|
||||
SIOCSARP,
|
||||
SIOCDARP,
|
||||
FIBMAP,
|
||||
FIONBIO,
|
||||
};
|
||||
|
@ -117,5 +119,7 @@ enum IOCtlNumber {
|
|||
#define SIOCGIFCONF SIOCGIFCONF
|
||||
#define SIOCADDRT SIOCADDRT
|
||||
#define SIOCDELRT SIOCDELRT
|
||||
#define SIOCSARP SIOCSARP
|
||||
#define SIOCDARP SIOCDARP
|
||||
#define FIBMAP FIBMAP
|
||||
#define FIONBIO FIONBIO
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue