bool PatchModel::remove_child(SharedPtr<ObjectModel> o) { assert(o->path().is_child_of(path())); assert(o->parent().get() == this); // Remove any connections which referred to this object, // since they can't possibly exist anymore for (Connections::iterator j = _connections->begin(); j != _connections->end(); ) { Connections::iterator next = j; ++next; SharedPtr<ConnectionModel> cm = PtrCast<ConnectionModel>(j->second); assert(cm); if (cm->src_port_path().parent() == o->path() || cm->src_port_path() == o->path() || cm->dst_port_path().parent() == o->path() || cm->dst_port_path() == o->path()) { INGEN_EMIT_THIS(removed_connection, cm); _connections->erase(j); // cuts our reference } j = next; } SharedPtr<PortModel> pm = PtrCast<PortModel>(o); if (pm) remove_port(pm); SharedPtr<NodeModel> nm = PtrCast<NodeModel>(o); if (nm) INGEN_EMIT_THIS(removed_node, nm); return true; }
bool NodeModel::remove_child(SharedPtr<ObjectModel> c) { assert(c->path().is_child_of(path())); assert(c->parent().get() == this); //bool ret = ObjectModel::remove_child(c); SharedPtr<PortModel> pm = PtrCast<PortModel>(c); assert(pm); remove_port(pm); //return ret; return true; }
int divert_ioctl(unsigned int cmd, struct divert_cf __user *arg) { struct divert_cf div_cf; struct divert_blk *div_blk; struct net_device *dev; int ret; switch (cmd) { case SIOCGIFDIVERT: DVDBG("SIOCGIFDIVERT, copy_from_user"); if (copy_from_user(&div_cf, arg, sizeof(struct divert_cf))) return -EFAULT; DVDBG("before check_args"); ret = check_args(&div_cf, &dev); if (ret) return ret; DVDBG("after checkargs"); div_blk = dev->divert; DVDBG("befre switch()"); switch (div_cf.cmd) { case DIVCMD_GETSTATUS: /* Now, just give the user the raw divert block * for him to play with :) */ if (copy_to_user(div_cf.arg1.ptr, dev->divert, sizeof(struct divert_blk))) return -EFAULT; break; case DIVCMD_GETVERSION: DVDBG("GETVERSION: checking ptr"); if (div_cf.arg1.ptr == NULL) return -EINVAL; DVDBG("GETVERSION: copying data to userland"); if (copy_to_user(div_cf.arg1.ptr, sysctl_divert_version, 32)) return -EFAULT; DVDBG("GETVERSION: data copied"); break; default: return -EINVAL; } break; case SIOCSIFDIVERT: if (copy_from_user(&div_cf, arg, sizeof(struct divert_cf))) return -EFAULT; ret = check_args(&div_cf, &dev); if (ret) return ret; div_blk = dev->divert; switch(div_cf.cmd) { case DIVCMD_RESET: div_blk->divert = 0; div_blk->protos = DIVERT_PROTO_NONE; memset(div_blk->tcp_dst, 0, MAX_DIVERT_PORTS * sizeof(u16)); memset(div_blk->tcp_src, 0, MAX_DIVERT_PORTS * sizeof(u16)); memset(div_blk->udp_dst, 0, MAX_DIVERT_PORTS * sizeof(u16)); memset(div_blk->udp_src, 0, MAX_DIVERT_PORTS * sizeof(u16)); return 0; case DIVCMD_DIVERT: switch(div_cf.arg1.int32) { case DIVARG1_ENABLE: if (div_blk->divert) return -EALREADY; div_blk->divert = 1; break; case DIVARG1_DISABLE: if (!div_blk->divert) return -EALREADY; div_blk->divert = 0; break; default: return -EINVAL; } break; case DIVCMD_IP: switch(div_cf.arg1.int32) { case DIVARG1_ENABLE: if (div_blk->protos & DIVERT_PROTO_IP) return -EALREADY; div_blk->protos |= DIVERT_PROTO_IP; break; case DIVARG1_DISABLE: if (!(div_blk->protos & DIVERT_PROTO_IP)) return -EALREADY; div_blk->protos &= ~DIVERT_PROTO_IP; break; default: return -EINVAL; } break; case DIVCMD_TCP: switch(div_cf.arg1.int32) { case DIVARG1_ENABLE: if (div_blk->protos & DIVERT_PROTO_TCP) return -EALREADY; div_blk->protos |= DIVERT_PROTO_TCP; break; case DIVARG1_DISABLE: if (!(div_blk->protos & DIVERT_PROTO_TCP)) return -EALREADY; div_blk->protos &= ~DIVERT_PROTO_TCP; break; default: return -EINVAL; } break; case DIVCMD_TCPDST: switch(div_cf.arg1.int32) { case DIVARG1_ADD: return add_port(div_blk->tcp_dst, div_cf.arg2.uint16); case DIVARG1_REMOVE: return remove_port(div_blk->tcp_dst, div_cf.arg2.uint16); default: return -EINVAL; } break; case DIVCMD_TCPSRC: switch(div_cf.arg1.int32) { case DIVARG1_ADD: return add_port(div_blk->tcp_src, div_cf.arg2.uint16); case DIVARG1_REMOVE: return remove_port(div_blk->tcp_src, div_cf.arg2.uint16); default: return -EINVAL; } break; case DIVCMD_UDP: switch(div_cf.arg1.int32) { case DIVARG1_ENABLE: if (div_blk->protos & DIVERT_PROTO_UDP) return -EALREADY; div_blk->protos |= DIVERT_PROTO_UDP; break; case DIVARG1_DISABLE: if (!(div_blk->protos & DIVERT_PROTO_UDP)) return -EALREADY; div_blk->protos &= ~DIVERT_PROTO_UDP; break; default: return -EINVAL; } break; case DIVCMD_UDPDST: switch(div_cf.arg1.int32) { case DIVARG1_ADD: return add_port(div_blk->udp_dst, div_cf.arg2.uint16); case DIVARG1_REMOVE: return remove_port(div_blk->udp_dst, div_cf.arg2.uint16); default: return -EINVAL; } break; case DIVCMD_UDPSRC: switch(div_cf.arg1.int32) { case DIVARG1_ADD: return add_port(div_blk->udp_src, div_cf.arg2.uint16); case DIVARG1_REMOVE: return remove_port(div_blk->udp_src, div_cf.arg2.uint16); default: return -EINVAL; } break; case DIVCMD_ICMP: switch(div_cf.arg1.int32) { case DIVARG1_ENABLE: if (div_blk->protos & DIVERT_PROTO_ICMP) return -EALREADY; div_blk->protos |= DIVERT_PROTO_ICMP; break; case DIVARG1_DISABLE: if (!(div_blk->protos & DIVERT_PROTO_ICMP)) return -EALREADY; div_blk->protos &= ~DIVERT_PROTO_ICMP; break; default: return -EINVAL; } break; default: return -EINVAL; } break; default: return -EINVAL; } return 0; }