| /* |
| * Copyright 2018, NICTA |
| * |
| * This software may be distributed and modified according to the terms of |
| * the GNU General Public License version 2. Note that NO WARRANTY is provided. |
| * See "LICENSE_GPLv2.txt" for details. |
| * |
| * @TAG(NICTA_GPL) |
| */ |
| |
| /* |
| * This file contains wrappers for various linux kernel api calls that we need |
| * to make from Cogent code. |
| */ |
| |
| inline $ty:(R (SysState, NetDeviceAbstractType) SysState) alloc_netdev_lo_ac($ty:(SysState) st) |
| { |
| $ty:(R (SysState, NetDeviceAbstractType) SysState) ret; |
| $ty:(NetDeviceAbstractType) dev; |
| |
| dev = alloc_netdev(0, "cglo", NET_NAME_UNKNOWN, cg_loopback_setup_ac); |
| if (!dev) { |
| ret.tag = TAG_ENUM_Error; |
| ret.Error = st; |
| } else { |
| ret.tag = TAG_ENUM_Success; |
| ret.Success.p1 = st; |
| ret.Success.p2 = dev; |
| } |
| |
| return ret; |
| } |
| |
| inline $ty:((SysState, NetDeviceAbstractType, NetAbstractType)) dev_net_set_ac($ty:((SysState, NetDeviceAbstractType, NetAbstractType)) args) |
| { |
| dev_net_set(args.p2, args.p3); |
| |
| return args; |
| } |
| |
| inline $ty:(RR (SysState, NetDeviceAbstractType) () ()) register_net_dev_ac($ty:((SysState, NetDeviceAbstractType)) args) |
| { |
| int err; |
| $ty:((SysState, NetDeviceAbstractType)) data; |
| $ty:(RR (SysState, NetDeviceAbstractType) () ()) ret; |
| |
| err = register_netdev(args.p2); |
| if (err) { |
| ret.p2.tag = TAG_ENUM_Error; |
| } else { |
| ret.p2.tag = TAG_ENUM_Success; |
| } |
| |
| data.p1 = args.p1; |
| data.p2 = args.p2; |
| |
| ret.p1 = data; |
| |
| return ret; |
| } |
| |
| inline $ty:((SysState, NetAbstractType)) assign_loopback_dev_in_net_ac($ty:((SysState, NetDeviceAbstractType, NetAbstractType)) args) |
| { |
| $ty:((SysState, NetAbstractType)) ret; |
| $ty:(NetAbstractType) net = args.p3; |
| |
| net->loopback_dev = args.p2; |
| |
| ret.p1 = args.p1; |
| ret.p2 = net; |
| |
| return ret; |
| } |
| |
| inline $ty:(SysState) free_netdev_ac($ty:((SysState, NetDeviceAbstractType)) args) |
| { |
| free_netdev(args.p2); |
| |
| return args.p1; |
| } |
| |
| inline $ty:(RR (SysState, NetDeviceAbstractType) () ()) netdev_alloc_pcpu_stats_ac($ty:((SysState, NetDeviceAbstractType)) args) |
| { |
| $ty:((SysState, NetDeviceAbstractType)) data; |
| $ty:(RR (SysState, NetDeviceAbstractType) () ()) ret; |
| $ty:(PCPULStats) stat; |
| |
| /* Ugly ugly type cast below, */ |
| (args.p2)->lstats = (struct pcpu_lstats *)netdev_alloc_pcpu_stats(*stat); |
| if (!(args.p2)->lstats) { |
| ret.p2.tag = TAG_ENUM_Error; |
| } else { |
| ret.p2.tag = TAG_ENUM_Success; |
| } |
| |
| data.p1 = args.p1; |
| data.p2 = args.p2; |
| ret.p1 = data; |
| |
| return ret; |
| } |
| |
| inline $ty:((SysState, NetDeviceAbstractType)) netdev_free_pcpu_stats_ac($ty:((SysState, NetDeviceAbstractType)) args) |
| { |
| dev_net(args.p2)->loopback_dev = NULL; |
| free_percpu((args.p2)->lstats); |
| |
| return args; |
| } |